Add template support

This commit is contained in:
2015-03-07 21:19:34 +01:00
parent c3c4c09c4a
commit 6a191e5d07
6 changed files with 9031 additions and 6 deletions
@@ -6,6 +6,7 @@
#= require ace/mode-coffee
#= require ace/mode-handlebars
#= require ace/mode-yaml
#= require ace/mode-haml
#= require tinymce-jquery
#= require_directory .
#= require_self
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -3,6 +3,7 @@ class HtmlEdit
#ACE
$('.html-content').each (i, el)->
text_field = $(el)
template_field = $("##{text_field.attr('id')}_template")
ace_div = $('<div></div>').addClass('ace-div')
text_field.after ace_div
ace_div.css
@@ -10,12 +11,24 @@ class HtmlEdit
height: '600px'
editor = ace.edit(ace_div.get(0))
editor.setTheme 'ace/theme/monokai'
editor.setValue text_field.val(), -1
editor.getSession().setMode 'ace/mode/handlebars'
if template_field.length
editor.setValue template_field.val(), -1
editor.getSession().setMode 'ace/mode/haml'
else
editor.setValue text_field.val(), -1
editor.getSession().setMode 'ace/mode/handlebars'
editor.getSession().setTabSize(2)
editor.getSession().setUseSoftTabs(true)
editor.getSession().on 'change', (e)->
text_field.val(editor.getValue()).change()
value = editor.getValue()
if template_field.length
try
template = Emblem.compile(Handlebars, value)
result_value = template(page_vars)
template_field.val value
text_field.val result_value
else
text_field.val value
text_field.hide()
#ace_div.hide()
template_field.hide()
@html_edit = new HtmlEdit()
+1 -1
View File
@@ -27,8 +27,8 @@ javascript:
.form-field= f.select :locale, Page.locales
.form-row
= f.label :body
br
= f.text_area :body, rows: 30, cols: 80, class: 'html-content'
= f.text_area :body_template
= collapsible_content 'Sidebar' do
.field
= f.label :sidebar