Store the processed html from the markdown text body field

This commit is contained in:
Amaia Castro
2016-12-13 17:01:50 +01:00
parent c69f1b3e83
commit 400b510b71
6 changed files with 44 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ App.MarkdownEditor =
textarea_content = element.find('textarea').val()
result = md.render(textarea_content)
element.find('#markdown-preview').html(result)
element.find('#markdown-result input').val(result)
initialize: ->
$('.markdown-editor').each ->

View File

@@ -36,7 +36,8 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont
:changelog,
:status,
:final_version,
:body
:body,
:body_html
)
end
end

View File

@@ -69,6 +69,9 @@
</div>
<div id="markdown-preview" class="small-12 medium-6 column">
</div>
<div id="markdown-result">
<%= f.hidden_field :body_html, label: false %>
</div>
</div>
</div>

View File

@@ -0,0 +1,5 @@
class AddBodyHtmlToDraftVersions < ActiveRecord::Migration
def change
add_column :legislation_draft_versions, :body_html, :text
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161205110441) do
ActiveRecord::Schema.define(version: 20161213144031) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -238,6 +238,7 @@ ActiveRecord::Schema.define(version: 20161205110441) do
t.datetime "hidden_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "body_html"
end
add_index "legislation_draft_versions", ["hidden_at"], name: "index_legislation_draft_versions_on_hidden_at", using: :btree

View File

@@ -35,7 +35,7 @@ feature 'Admin legislation draft versions' do
end
context 'Create' do
scenario 'Valid legislation draft_version' do
scenario 'Valid legislation draft version' do
process = create(:legislation_process, title: 'An example legislation process')
visit admin_root_path
@@ -63,4 +63,34 @@ feature 'Admin legislation draft versions' do
expect(page).to have_content 'Version 3'
end
end
context 'Update' do
scenario 'Valid legislation draft version', :js do
process = create(:legislation_process, title: 'An example legislation process')
draft_version = create(:legislation_draft_version, title: 'Version 1', process: process)
visit admin_root_path
within('#side_menu') do
click_link "Collaborative Legislation"
end
click_link "All"
expect(page).to have_content 'An example legislation process'
click_link 'An example legislation process'
click_link 'Text'
click_link 'Version 1'
fill_in 'legislation_draft_version_title', with: 'Version 1b'
fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\nParagraph\r\n>Quote'
click_button 'Save changes'
expect(page).to have_content 'Version 1b'
expect(draft_version.reload.body_html).to eq("<h1>Version 1 body\\r\\nParagraph\\r\\n&gt;Quote</h1>\r\n")
end
end
end