Merge branch 'master' of github.com:bterkuile/cmtool

This commit is contained in:
2015-06-09 10:34:12 +02:00
8 changed files with 76 additions and 25 deletions
+14 -14
View File
@@ -83,7 +83,7 @@ GEM
tzinfo (~> 1.1)
arel (6.0.0)
bcrypt (3.1.10)
bourbon (4.2.1)
bourbon (4.2.2)
sass (~> 3.4)
thor
builder (3.2.2)
@@ -98,7 +98,7 @@ GEM
cocaine (0.5.7)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.0)
coffee-script (2.3.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.9.1)
@@ -106,7 +106,7 @@ GEM
mime-types (~> 1.15)
multi_json (~> 1.0)
rest-client (~> 1.6.1)
daemons (1.1.9)
daemons (1.2.2)
devise (3.4.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@@ -119,7 +119,7 @@ GEM
activemodel
erubis (2.7.0)
eventmachine (1.0.7)
execjs (2.4.0)
execjs (2.5.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
@@ -127,10 +127,10 @@ GEM
railties (>= 3.0.0)
font-awesome-rails (4.3.0.0)
railties (>= 3.2, < 5.0)
foundation-rails (5.5.1.0)
foundation-rails (5.5.1.1)
railties (>= 3.1.0)
sass (>= 3.3.0, < 3.5)
globalid (0.3.3)
globalid (0.3.4)
activesupport (>= 4.1.0)
hike (1.2.3)
i18n (0.7.0)
@@ -159,7 +159,7 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.3)
pry-rails (0.3.4)
pry (>= 0.9.10)
rack (1.6.0)
rack-test (0.6.3)
@@ -177,11 +177,11 @@ GEM
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.5)
rails-dom-testing (1.0.6)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
railties (4.2.0)
actionpack (= 4.2.0)
@@ -195,9 +195,9 @@ GEM
rest-client (1.6.8)
mime-types (~> 1.16)
rdoc (>= 2.4.2)
rspec-core (3.2.1)
rspec-core (3.2.3)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.0)
rspec-expectations (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-its (1.2.0)
@@ -216,13 +216,13 @@ GEM
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
sass (3.4.13)
sass-rails (5.0.1)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1)
slim (3.0.2)
slim (3.0.3)
temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1)
slim-rails (3.0.1)
@@ -250,7 +250,7 @@ GEM
eventmachine (~> 1.0)
rack (~> 1.0)
thor (0.19.1)
thread_safe (0.3.4)
thread_safe (0.3.5)
tilt (1.4.1)
tinymce-rails (4.1.6)
railties (>= 3.1.1)
@@ -21,6 +21,9 @@ $ ->
url = $(@).attr('href')
iframe = $('#preview-modal iframe')
params =
name: $('#page_name').val()
menu_text: $('#page_menu_text').val()
title: $('#page_title').val()
body: $('#page_body').val()
sidebar: $('#page_sidebar').val()
footer: $('#page_footer').val()
@@ -3,10 +3,4 @@ class Collapsible
$('.collapsible-container').each (i, el) ->
$(el).find('.collapsible-title').click -> $(el).toggleClass('collapsed')
#FIXME this is a hack for expanding on load for migration comments
$('.migration-comments .thread a').click()
@collapsible = new Collapsible()
@@ -1,6 +1,7 @@
class HtmlEdit
setup: ->
#ACE
locale_field = $('#page_locale')
$('.html-content').each (i, el)->
text_field = $(el)
template_field = $("##{text_field.attr('id')}_template")
@@ -14,21 +15,45 @@ class HtmlEdit
if template_field.length
editor.setValue template_field.val(), -1
editor.getSession().setMode 'ace/mode/haml'
console.log "Editing haml"
else
editor.setValue text_field.val(), -1
editor.getSession().setMode 'ace/mode/handlebars'
console.log "Editing handlebars"
editor.getSession().setTabSize(2)
editor.getSession().setUseSoftTabs(true)
editor.getSession().on 'change', (e)->
template_vars = page_vars
if locale = locale_field.val()
template_vars = template_vars[locale] if template_vars[locale]
rebuild_html = ->
value = editor.getValue()
if template_field.length
try
template = Emblem.compile(Handlebars, value)
result_value = template(page_vars)
result_value = template(template_vars)
template_field.val value
text_field.val result_value
else
text_field.val value
editor.getSession().on 'change', rebuild_html
locale_field.change ->
locale = $(this).val()
template_vars = page_vars[locale] if page_vars[locale]
rebuild_html()
text_field.hide()
template_field.hide()
@html_edit = new HtmlEdit()
Handlebars.registerHelper "link-to", (url, args..., options = {})->
unless not url or url.match(/^http|^\/\w{2}\//)
# Starts with http or /:locale/ explicitly
if options.hash and options.hash.hasOwnProperty 'locale'
if locale = options.hash.locale
url = "/#{locale}/#{url}".replace('//', '/')
else if locale = $('#page_locale').val()
url = "/#{locale}/#{url}".replace('//', '/')
if options.fn
text = options.fn(this)
else
text = args[0]
link = "<a href='#{url}'>#{text}</a>"
new Handlebars.SafeString(link)
@@ -3,7 +3,7 @@ class YmlEdit
#ACE
$('.yml-content').each (i, el)->
text_field = $(el)
ace_div = $('<div></div>').addClass('ace-div').html(text_field.val())
ace_div = $('<div></div>').addClass('ace-div') #.html(text_field.val())
text_field.after ace_div
ace_div.css
width: '100%'
@@ -11,6 +11,7 @@ class YmlEdit
editor = ace.edit(ace_div.get(0))
editor.setTheme 'ace/theme/monokai'
editor.getSession().setMode 'ace/mode/yaml'
editor.getSession().setValue text_field.val()
editor.getSession().setTabSize(2)
editor.getSession().setUseSoftTabs(true)
editor.getSession().on 'change', (e)->
+1 -1
View File
@@ -9,7 +9,7 @@ module Cmtool
def self.all_as_object
all.each.with_object Hash.new do |yml_file, obj|
yml_obj = YAML.load(yml_file.body) rescue nil
obj.merge!( yml_obj ) if yml_obj
obj.deep_merge!( yml_obj ) if yml_obj
end
end
end
+1 -1
View File
@@ -9,7 +9,7 @@
tbody
- @yml_files.each do |yml_file|
tr
td= link_to yml_file.name, cmtool.yml_file_path(yml_file)
td= link_to yml_file.name, cmtool.edit_yml_file_path(yml_file)
= edit_td yml_file
= destroy_td yml_file
- else
+28
View File
@@ -0,0 +1,28 @@
require 'spec_helper'
describe Cmtool::YmlFile do
describe ".all_as_object" do
it "combines the files using deep merge" do
described_class.create body: <<-YML.strip_heredoc
nl:
android:
link: <a>l</a>
YML
described_class.create body: <<-YML.strip_heredoc
nl:
android:
title: Mozo at Play store
YML
result = described_class.all_as_object
result.should =~ {
"nl"=> {
"android" => {
"title"=>"Mozo at Play store",
"link"=>"<a>l</a>"
}
}
}
end
end
end