app/helpers/cms/fortress/sprocket_helper.rb in cms-fortress-1.3.5 vs app/helpers/cms/fortress/sprocket_helper.rb in cms-fortress-1.3.6

- old
+ new

@@ -1,32 +1,27 @@ module Cms::Fortress::SprocketHelper include TinyMCE::Rails::Helper def tinymce_init - path = File.join(Rails.root, 'config', 'tinymce.yml') - if File.exist?(path) - config = YAML.load_file(path) - else - config = {} - end + config = Cms::Fortress::Settings.new(:tinymce).to_h rescue {} options = { menubar: "tools format view", toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fullscreen code | image fmedia link", toolbar2: "", plugins: ["code", "fullscreen", "media", "link", "table"], language: "en" - }.stringify_keys.merge(config) + }.merge(config) <<-EOF tinymce.init({ - #{configuration_from_options(options)}, + #{configuration_from_options(options)} + #{configuration_from_options_as_string(options)} selector: 'textarea[data-cms-rich-text]', link_list: CmsFortress.media.othersUrl(), setup: function(ed) { - ed.addButton('image', { title: 'Insert Image', onclick: function() { return CmsFortress.media.showImageDialog(ed); } @@ -38,22 +33,30 @@ stateSelector: ['img[data-mce-object=video]', 'img[data-mce-object=iframe]'], onclick: function() { return CmsFortress.media.showVideoDialog(ed); } }); - } - }); EOF end private + def configuration_from_options_as_string(options) + config = options.map do |k, v| + "#{k.to_s.gsub('[plain]', '')}: #{v}," if k.to_s =~ /\[plain\]/ + end + config.join() if config.present? + end + def configuration_from_options(options) - options.map do |k, v| - v.is_a?(Array) ? "#{k}: #{v}" : "#{k}: #{boolean_value(v)}" - end.join(',') + config = options.map do |k, v| + unless k.to_s =~ /\[plain\]/ + v.is_a?(Array) ? "#{k}: #{v}," : "#{k}: #{boolean_value(v)}," + end + end + config.join() end def boolean_value(v) [true, false].include?(v) ? "#{v}" : "'#{v}'" end