liquid_cms 0.2.1.1 → 0.2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. data/CHANGELOG.rdoc +7 -0
  2. data/README.rdoc +15 -1
  3. data/TODO.rdoc +0 -2
  4. data/app/controllers/cms/assets_controller.rb +20 -6
  5. data/app/controllers/cms/components_controller.rb +11 -3
  6. data/app/controllers/cms/pages_controller.rb +15 -4
  7. data/app/helpers/cms/common_helper.rb +31 -31
  8. data/app/liquid/cms_paperclip_extension.rb +75 -3
  9. data/app/models/cms/asset.rb +1 -1
  10. data/app/models/cms/component.rb +3 -3
  11. data/app/views/cms/assets/_form.html.erb +1 -1
  12. data/app/views/cms/assets/update.js.rjs +1 -0
  13. data/app/views/cms/components/update.js.rjs +1 -0
  14. data/app/views/cms/pages/_form.html.erb +1 -1
  15. data/app/views/cms/pages/update.js.rjs +1 -0
  16. data/app/views/layouts/cms.html.erb +4 -3
  17. data/generators/liquid_cms/liquid_cms_generator.rb +1 -0
  18. data/generators/liquid_cms/templates/config/locales/cms/en.yml +4 -0
  19. data/generators/liquid_cms/templates/migration_rev2.rb +13 -0
  20. data/generators/liquid_cms/templates/public/cms/codemirror/LICENSE +16 -20
  21. data/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.css +68 -0
  22. data/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.js +2197 -0
  23. data/generators/liquid_cms/templates/public/cms/codemirror/lib/overlay.js +51 -0
  24. data/generators/liquid_cms/templates/public/cms/codemirror/lib/runmode.js +27 -0
  25. data/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/clike.js +247 -0
  26. data/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/index.html +102 -0
  27. data/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/clojure.js +207 -0
  28. data/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/index.html +85 -0
  29. data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/LICENSE +22 -0
  30. data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/coffeescript.js +325 -0
  31. data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/index.html +722 -0
  32. data/generators/liquid_cms/templates/public/cms/codemirror/mode/css/css.js +124 -0
  33. data/generators/liquid_cms/templates/public/cms/codemirror/mode/css/index.html +56 -0
  34. data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.css +3 -0
  35. data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.js +13 -0
  36. data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/index.html +99 -0
  37. data/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/haskell.js +242 -0
  38. data/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/index.html +60 -0
  39. data/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/htmlmixed.js +79 -0
  40. data/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/index.html +52 -0
  41. data/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/index.html +78 -0
  42. data/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/javascript.js +352 -0
  43. data/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/index.html +38 -0
  44. data/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/jinja2.js +42 -0
  45. data/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/index.html +72 -0
  46. data/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/lua.js +140 -0
  47. data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/index.html +340 -0
  48. data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.css +10 -0
  49. data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.js +230 -0
  50. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/index.html +33 -0
  51. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/ntriples.js +172 -0
  52. data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/LICENSE +7 -0
  53. data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/index.html +49 -0
  54. data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/pascal.js +138 -0
  55. data/generators/liquid_cms/templates/public/cms/codemirror/mode/php/index.html +49 -0
  56. data/generators/liquid_cms/templates/public/cms/codemirror/mode/php/php.js +116 -0
  57. data/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/index.html +63 -0
  58. data/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/plsql.js +217 -0
  59. data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/LICENSE.txt +21 -0
  60. data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/index.html +123 -0
  61. data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/python.js +320 -0
  62. data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/LICENSE +24 -0
  63. data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/index.html +74 -0
  64. data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/r.js +141 -0
  65. data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/index.html +526 -0
  66. data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.css +75 -0
  67. data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.js +333 -0
  68. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/LICENSE +24 -0
  69. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/index.html +172 -0
  70. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/ruby.js +195 -0
  71. data/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/index.html +65 -0
  72. data/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/scheme.js +202 -0
  73. data/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/index.html +56 -0
  74. data/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/smalltalk.js +122 -0
  75. data/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/index.html +41 -0
  76. data/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/sparql.js +143 -0
  77. data/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/index.html +96 -0
  78. data/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/stex.js +167 -0
  79. data/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/index.html +103 -0
  80. data/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/velocity.js +146 -0
  81. data/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/index.html +42 -0
  82. data/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/xml.js +231 -0
  83. data/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/index.html +60 -0
  84. data/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/xmlpure.js +481 -0
  85. data/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/index.html +68 -0
  86. data/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/yaml.js +95 -0
  87. data/generators/liquid_cms/templates/public/cms/codemirror/theme/cobalt.css +17 -0
  88. data/generators/liquid_cms/templates/public/cms/codemirror/theme/default.css +19 -0
  89. data/generators/liquid_cms/templates/public/cms/codemirror/theme/eclipse.css +24 -0
  90. data/generators/liquid_cms/templates/public/cms/codemirror/theme/elegant.css +9 -0
  91. data/generators/liquid_cms/templates/public/cms/codemirror/theme/neat.css +8 -0
  92. data/generators/liquid_cms/templates/public/cms/codemirror/theme/night.css +20 -0
  93. data/generators/liquid_cms/templates/public/cms/javascripts/cms.js +1 -1
  94. data/generators/liquid_cms/templates/public/cms/javascripts/codemirror_custom.js +96 -0
  95. data/generators/liquid_cms/templates/public/cms/stylesheets/codemirror_changes.css +26 -0
  96. data/generators/liquid_cms/templates/public/cms/stylesheets/liquid.css +7 -0
  97. data/generators/liquid_cms/templates/public/cms/stylesheets/simple_form.css +0 -8
  98. data/lib/liquid_cms/version.rb +1 -1
  99. data/liquid_cms.gemspec +0 -1
  100. data/test/functional/assets_controller_test.rb +35 -20
  101. data/test/functional/components_controller_test.rb +15 -5
  102. data/test/functional/pages_controller_test.rb +19 -6
  103. data/test/rails_app/config/environment.rb +1 -1
  104. data/test/rails_app/config/locales/cms/en.yml +19 -4
  105. data/test/rails_app/db/migrate/20110511161859_create_liquid_cms_upgrade_rev2.rb +13 -0
  106. data/test/unit/asset_test.rb +1 -1
  107. metadata +100 -58
  108. data/generators/liquid_cms/templates/public/cms/codemirror/css/csscolors.css +0 -55
  109. data/generators/liquid_cms/templates/public/cms/codemirror/css/docs.css +0 -158
  110. data/generators/liquid_cms/templates/public/cms/codemirror/css/font.js +0 -15
  111. data/generators/liquid_cms/templates/public/cms/codemirror/css/jscolors.css +0 -59
  112. data/generators/liquid_cms/templates/public/cms/codemirror/css/sparqlcolors.css +0 -43
  113. data/generators/liquid_cms/templates/public/cms/codemirror/css/xmlcolors.css +0 -55
  114. data/generators/liquid_cms/templates/public/cms/codemirror/js/codemirror.js +0 -582
  115. data/generators/liquid_cms/templates/public/cms/codemirror/js/editor.js +0 -1671
  116. data/generators/liquid_cms/templates/public/cms/codemirror/js/highlight.js +0 -68
  117. data/generators/liquid_cms/templates/public/cms/codemirror/js/mirrorframe.js +0 -81
  118. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsecss.js +0 -161
  119. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsedummy.js +0 -32
  120. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsehtmlmixed.js +0 -93
  121. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsejavascript.js +0 -359
  122. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsesparql.js +0 -162
  123. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsexml.js +0 -291
  124. data/generators/liquid_cms/templates/public/cms/codemirror/js/select.js +0 -699
  125. data/generators/liquid_cms/templates/public/cms/codemirror/js/stringstream.js +0 -159
  126. data/generators/liquid_cms/templates/public/cms/codemirror/js/tokenize.js +0 -57
  127. data/generators/liquid_cms/templates/public/cms/codemirror/js/tokenizejavascript.js +0 -174
  128. data/generators/liquid_cms/templates/public/cms/codemirror/js/undo.js +0 -413
  129. data/generators/liquid_cms/templates/public/cms/codemirror/js/unittests.js +0 -44
  130. data/generators/liquid_cms/templates/public/cms/codemirror/js/util.js +0 -133
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.2.2.0
2
+
3
+ * Enhancements
4
+ * Optimize paperclip image dimension lookup in to_liquid calls. To make use of optimized paperclip attachments in your custom to_liquid methods, add a column to your table in a migration. See the README under the customization section for more information.
5
+ * Update to codemirror v2
6
+ * Ctrl+s now uses ajax for editing pages, textual assets and textual components in order to streamline the editing process.
7
+
1
8
  == 0.2.1.1
2
9
 
3
10
  * Fixes
data/README.rdoc CHANGED
@@ -29,7 +29,7 @@ Run the generator:
29
29
  Configure the engine in config/initializers/cms/liquid_cms.rb:
30
30
 
31
31
  If you wish to run the cms under multiple "contexts" (ie. a cms each for a company, business, customer, etc.) then you need to perform the following steps:
32
-
32
+
33
33
  * Set the *context_class* attribute to your apps context class:
34
34
 
35
35
  config.context_class = :Company
@@ -58,6 +58,20 @@ In order to expose data in your application in the templates, liquid filters, dr
58
58
 
59
59
  A set of filters, drops and tags are provided in addition to the defaults provided by liquid. The documentation link accessible in the CMS provides additional details.
60
60
 
61
+ If you're using paperclip images in any models and exposing them via to_liquid, you can add an addtional column to your table to optimize dimension lookup.
62
+
63
+ class Customer
64
+ has_attached :photo
65
+
66
+ def to_liquid
67
+ photo.to_liquid
68
+ end
69
+ end
70
+
71
+ change_table :customers do |t|
72
+ t.text :cms_photo_dimensions # field name must be named after the paperclip name. ie. :cms_{paperclip name}_dimensions
73
+ end
74
+
61
75
  = Upgrading
62
76
 
63
77
  To upgrade the liquid_cms engine once you've installed a newer gem, simply re-run the liquid_cms generator. If any differences are found in files, you'll be prompted to overwrite or compare versions.
data/TODO.rdoc CHANGED
@@ -1,8 +1,6 @@
1
1
  * Implement a cleaner, more functional UI.
2
- * Vestal versions is used, but not exposed via the UI currently to go back to previous versions.
3
2
  * No functions are currently limited to specific user roles. All CMS users can perform the same actions.
4
3
  * Implement caching and expiration logic.
5
4
  * Provide example apache/nginx/etc. conf files that properly scope cms assets for each context.
6
5
  * Generate CMS documentation from rdoc comments in source files?
7
- * Search functions. Find templates based on search text.
8
6
  * Missing tests... add more coverage.
@@ -30,10 +30,21 @@ class Cms::AssetsController < Cms::MainController
30
30
  @asset.assign_ordered_attributes params[:cms_asset]
31
31
 
32
32
  if @asset.save
33
- flash[:notice] = t('assets.flash.updated')
34
- redirect_to cms_root_path
33
+ respond_to do |format|
34
+ format.html {
35
+ redirect_to edit_cms_asset_path(@asset), :notice => t('assets.flash.updated')
36
+ }
37
+ format.js {
38
+ flash.now[:notice] = t('assets.flash.updated')
39
+ }
40
+ end
35
41
  else
36
- render :action => 'edit'
42
+ respond_to do |format|
43
+ format.html {
44
+ render :action => 'edit'
45
+ }
46
+ format.js
47
+ end
37
48
  end
38
49
  end
39
50
 
@@ -42,7 +53,7 @@ class Cms::AssetsController < Cms::MainController
42
53
  @asset.destroy
43
54
 
44
55
  flash[:notice] = t('assets.flash.deleted')
45
-
56
+
46
57
  respond_to do |format|
47
58
  format.html { redirect_to cms_root_path }
48
59
  end
@@ -62,10 +73,13 @@ protected
62
73
  # remove meta values since we only want the key names
63
74
  # new values will be provided for the new asset
64
75
  asset.meta_data = meta_asset.meta_data.collect{|m| {:name => m[:name], :value => ''}}
76
+ end
65
77
 
78
+ dims_asset = @context.assets.tagged_with(curr_tag).first :conditions => 'custom_width is not null and custom_height is not null'
79
+ if dims_asset
66
80
  # assign custom dims
67
- asset.custom_width = meta_asset.custom_width
68
- asset.custom_height = meta_asset.custom_height
81
+ asset.custom_width = dims_asset.custom_width
82
+ asset.custom_height = dims_asset.custom_height
69
83
  end
70
84
 
71
85
  asset
@@ -13,15 +13,23 @@ class Cms::ComponentsController < Cms::MainController
13
13
  end
14
14
 
15
15
  def update
16
+ edit_url = {:controller => 'cms/components', :action => 'edit', :url => @path}
17
+
16
18
  if Cms::Component.editable?(@path)
17
19
  @component = Cms::Component.new(@context, @path)
18
20
  @component.write params[:file_content]
19
21
 
20
- flash[:notice] = "The component file has been updated."
21
- redirect_to cms_root_path
22
+ respond_to do |format|
23
+ format.html {
24
+ redirect_to edit_url, :notice => t('components.flash.updated')
25
+ }
26
+ format.js {
27
+ flash.now[:notice] = t('components.flash.updated')
28
+ }
29
+ end
22
30
  else
23
31
  flash[:error] = "Not an editable component."
24
- redirect_to :controller => 'cms/components', :action => 'edit', :url => @path
32
+ redirect_to edit_url
25
33
  end
26
34
  end
27
35
 
@@ -26,10 +26,21 @@ class Cms::PagesController < Cms::MainController
26
26
  def update
27
27
  @page = @context.pages.find params[:id]
28
28
  if @page.update_attributes(params[:cms_page])
29
- flash[:notice] = t('pages.flash.updated')
30
- redirect_to edit_cms_page_path(@page)
29
+ respond_to do |format|
30
+ format.html {
31
+ redirect_to edit_cms_page_path(@page), :notice => t('pages.flash.updated')
32
+ }
33
+ format.js {
34
+ flash.now[:notice] = t('pages.flash.updated')
35
+ }
36
+ end
31
37
  else
32
- render :action => 'edit'
38
+ respond_to do |format|
39
+ format.html {
40
+ render :action => 'edit'
41
+ }
42
+ format.js
43
+ end
33
44
  end
34
45
  end
35
46
 
@@ -38,7 +49,7 @@ class Cms::PagesController < Cms::MainController
38
49
  @page.destroy
39
50
 
40
51
  flash[:notice] = t('pages.flash.deleted')
41
-
52
+
42
53
  respond_to do |format|
43
54
  format.html { redirect_to cms_root_path }
44
55
  format.js
@@ -13,48 +13,48 @@ module Cms::CommonHelper
13
13
 
14
14
  def cms_flash_message
15
15
  type = (flash[:error] ? :error : :notice)
16
- javascript_tag("document.observe('dom:loaded', function(){ humanMsg.displayMsg('#{escape_javascript(flash[type])}', '#{type}');})") if flash[type].present?
16
+ flash[type].present? ? "humanMsg.displayMsg('#{escape_javascript(flash[type])}', '#{type}')" : nil
17
+ end
18
+
19
+ def load_cms_flash_message
20
+ msg = cms_flash_message
21
+ msg.present? ? javascript_tag("document.observe('dom:loaded', function(){ #{msg} })") : nil
17
22
  end
18
23
 
19
24
  def cms_row_class
20
25
  cycle 'dark', 'light'
21
26
  end
22
27
 
23
- def codemirror_edit(content_type, form, content_id)
24
- js_options = case content_type
28
+ def cms_ajax_update_form(page, object, path)
29
+ if object.errors.empty?
30
+ page << cms_flash_message
31
+ else
32
+ page.replace_html 'content', :file => "cms/#{path}/edit.html.erb"
33
+ end
34
+ end
35
+
36
+ def codemirror_edit(content_type, form, content_id, use_ajax = true, liquid_support = false)
37
+ mode = nil
38
+
39
+ case content_type
25
40
  when "text/css"
26
- <<-JS
27
- parserfile: ["../../javascripts/parseliquid.js", "parsecss.js"],
28
- stylesheet: ["/cms/codemirror/css/csscolors.css", "/cms/stylesheets/liquidcolors.css"],
29
- JS
41
+ mode = 'css'
42
+ content_for :cms_styles do
43
+ javascript_include_tag '/cms/codemirror/mode/css/css'
44
+ end
30
45
  when "text/javascript"
31
- <<-JS
32
- parserfile: ["../../javascripts/parseliquid.js", "tokenizejavascript.js", "parsejavascript.js"],
33
- stylesheet: ["/cms/codemirror/css/jscolors.css", "/cms/stylesheets/liquidcolors.css"],
34
- JS
46
+ mode = 'javascript'
47
+ content_for :cms_styles do
48
+ javascript_include_tag '/cms/codemirror/mode/javascript/javascript'
49
+ end
35
50
  else
36
- <<-JS
37
- parserfile: ["../../javascripts/parseliquid.js"],
38
- stylesheet: ["/cms/codemirror/css/xmlcolors.css", "/cms/stylesheets/liquidcolors.css"],
39
- JS
51
+ mode = 'htmlmixed'
52
+ content_for :cms_styles do
53
+ javascript_include_tag '/cms/codemirror/mode/htmlmixed/htmlmixed'
54
+ end
40
55
  end
41
56
 
42
- javascript_tag do
43
- <<-JS
44
- var editor = CodeMirror.fromTextArea("#{content_id}", {
45
- #{js_options}
46
- path: "/cms/codemirror/js/",
47
- textWrapping: false,
48
- height: '600px',
49
- width: '89%',
50
- saveFunction: function() {
51
- var form = $$('#{form}').first();
52
- $('#{content_id}').setValue(editor.getCode());
53
- form.submit();
54
- }
55
- });
56
- JS
57
- end
57
+ javascript_tag %(initCodemirror('#{mode}', $$('#{form}').first(), $('#{content_id}'), #{use_ajax}, #{liquid_support}))
58
58
  end
59
59
 
60
60
  def file_type_icon(file_name)
@@ -3,14 +3,86 @@ module Paperclip
3
3
  extend ActiveSupport::Memoizable
4
4
 
5
5
  def to_liquid
6
- {}.tap do |h|
6
+ style_hash = {}
7
+
8
+ style_hash.tap do |h|
7
9
  all_styles = self.styles.keys + ['original']
8
10
  all_styles.each do |style|
9
- g = Paperclip::Geometry.from_file(self.path(style)) rescue nil
10
- h[style.to_s] = {'width' => g.width.to_i, 'height' => g.height.to_i, 'url' => self.url(style)} unless g.nil?
11
+ h[style.to_s] = find_geometry_dims(style)
12
+ h[style.to_s]['url'] = self.url(style) if h[style.to_s].present?
11
13
  end
12
14
  end
15
+
16
+ save_geometry_dims style_hash
17
+
18
+ style_hash
13
19
  end
14
20
  memoize :to_liquid
21
+
22
+ # clear out the dimension attribute when post processing
23
+ # it'll be updated on the next render via to_liquid
24
+ def post_process_with_dimension_attribute_clear
25
+ key = dimension_key
26
+
27
+ if instance.has_attribute?(key)
28
+ instance.send("#{key}=", nil)
29
+ end
30
+
31
+ post_process_without_dimension_attribute_clear
32
+ end
33
+
34
+ alias_method_chain :post_process, :dimension_attribute_clear
35
+
36
+ protected
37
+ def dimension_key
38
+ "cms_#{name}_dimensions"
39
+ end
40
+
41
+ def find_geometry_dims(style)
42
+ key = dimension_key
43
+
44
+ if instance.has_attribute?(key)
45
+ # dimension attr found
46
+ values = YAML::load(instance.send(key) || '{}')
47
+ if values.blank?
48
+ # no saved entry
49
+ geometry_dims(style)
50
+ else
51
+ # saved entry
52
+ dimensions = values[style.to_s]
53
+ if dimensions.blank?
54
+ # empty dimensions for the given style
55
+ geometry_dims(style)
56
+ else
57
+ # valid dimensions for the given style
58
+ {'width' => dimensions['width'].to_i, 'height' => dimensions['height'].to_i}
59
+ end
60
+ end
61
+ else
62
+ log %{To optimize image data in your liquid templates, add a text column named "#{key}" to your "#{instance.class.table_name}" table.}
63
+ # no dimensions found
64
+ geometry_dims(style)
65
+ end
66
+ end
67
+
68
+ def save_geometry_dims(style_hash)
69
+ key = dimension_key
70
+
71
+ if instance.has_attribute?(key) && YAML::load(instance.send(key) || '{}').all?{|k,v| v.blank?} && style_hash.present?
72
+ # deep copy hash
73
+ temp_hash = Marshal.load(Marshal.dump(style_hash))
74
+ # remove blank styles
75
+ temp_hash.delete_if{|k,v| v.blank?}
76
+ # and remove the urls
77
+ temp_hash.each{|k,v| v.delete_if{|k2,v2| k2 == 'url'}}
78
+
79
+ instance.update_attribute key, temp_hash.to_yaml if temp_hash.present?
80
+ end
81
+ end
82
+
83
+ def geometry_dims(style)
84
+ g = Paperclip::Geometry.from_file(self.path(style)) rescue nil
85
+ g.nil? ? {} : {'width' => g.width.to_i, 'height' => g.height.to_i}
86
+ end
15
87
  end
16
88
  end
@@ -81,7 +81,7 @@ module Cms
81
81
  end
82
82
 
83
83
  def editable?
84
- !(asset_content_type =~ /(javascript|css|xml|html)$/).blank?
84
+ Cms::Component.editable?(asset_file_name)
85
85
  end
86
86
 
87
87
  def file_content
@@ -2,7 +2,7 @@ require 'zip/zip'
2
2
 
3
3
  class Cms::Component
4
4
  attr_reader :path
5
-
5
+
6
6
  def initialize(context, path = nil)
7
7
  @context = context
8
8
  @path = self.class.clean_path(path) if path
@@ -67,7 +67,7 @@ class Cms::Component
67
67
  end if exist
68
68
  end
69
69
  end
70
-
70
+
71
71
  def delete
72
72
  return false if @path.blank?
73
73
 
@@ -78,7 +78,7 @@ class Cms::Component
78
78
  end
79
79
 
80
80
  def self.editable?(file)
81
- Cms.editable_component_exts.include?(File.extname(file).downcase)
81
+ file.present? && Cms.editable_component_exts.include?(File.extname(file).downcase)
82
82
  end
83
83
 
84
84
  protected
@@ -25,7 +25,7 @@
25
25
  <%= f.input :file_content, :as => :text, :input_html => {:rows => 40, :cols => nil} %>
26
26
  </div>
27
27
 
28
- <%= codemirror_edit Cms::Editable::content_type(@asset.asset_file_name), 'form.simple_form', 'cms_asset_file_content' %>
28
+ <%= codemirror_edit Cms::Editable::content_type(@asset.asset_file_name), 'form.simple_form', 'cms_asset_file_content', !@asset.new_record? %>
29
29
  <% end %>
30
30
 
31
31
  <div class="dimensions">
@@ -0,0 +1 @@
1
+ cms_ajax_update_form page, @asset, 'assets'
@@ -0,0 +1 @@
1
+ page << cms_flash_message
@@ -9,4 +9,4 @@
9
9
  <%= f.commit_button_or_cancel %>
10
10
  <% end %>
11
11
 
12
- <%= codemirror_edit @page.content_type, 'form.simple_form.cms_page', 'cms_page_content' %>
12
+ <%= codemirror_edit @page.content_type, 'form.simple_form.cms_page', 'cms_page_content', !@page.new_record?, true %>
@@ -0,0 +1 @@
1
+ cms_ajax_update_form page, @page, 'pages'
@@ -6,7 +6,8 @@
6
6
  <title><%= t 'pages.layout.title' %></title>
7
7
  <%= javascript_include_tag 'prototype', 'effects' %>
8
8
  <%= javascript_include_tag '/cms/javascripts/humanmsg', '/cms/javascripts/cookiejar', '/cms/javascripts/cms', '/cms/javascripts/livepipe', '/cms/javascripts/tabs', :cache => 'cms_scripts' %>
9
- <%= javascript_include_tag '/cms/codemirror/js/codemirror' %>
9
+ <%= javascript_include_tag '/cms/codemirror/lib/codemirror', '/cms/codemirror/mode/javascript/javascript', '/cms/codemirror/mode/css/css', '/cms/codemirror/mode/xml/xml', '/cms/codemirror/lib/overlay', '/cms/javascripts/codemirror_custom', :cache => 'codemirror_scripts' %>
10
+ <%= stylesheet_link_tag '/cms/codemirror/lib/codemirror', '/cms/codemirror/theme/default', '/cms/stylesheets/codemirror_changes', :cache => 'codemirror_styles' %>
10
11
  <%= stylesheet_link_tag '/cms/stylesheets/simple_form' %>
11
12
  <%= stylesheet_link_tag '/cms/stylesheets/clearfix', '/cms/stylesheets/humanmsg', '/cms/stylesheets/styles', '/cms/stylesheets/sidebar', :cache => 'cms_styles' %>
12
13
  <%= stylesheet_link_tag '/cms/stylesheets/themes/dark' %>
@@ -26,11 +27,11 @@
26
27
  <div id="outer-container" class="clearfix">
27
28
  <div id="sidebar" class="shadow curved">
28
29
  <%= render 'cms/shared/sidebar' %>
29
- </div>
30
+ </div>
30
31
 
31
32
  <div id="content">
32
33
  <%= yield %>
33
- <%= cms_flash_message %>
34
+ <%= load_cms_flash_message %>
34
35
  </div>
35
36
  </div>
36
37
  </body>
@@ -6,6 +6,7 @@ class LiquidCmsGenerator < Rails::Generator::Base
6
6
  # migrations
7
7
  m.migration_template 'migration.rb', File.join('db', 'migrate'), :migration_file_name => 'create_liquid_cms_setup'
8
8
  m.migration_template 'migration_rev1.rb', File.join('db', 'migrate'), :migration_file_name => 'create_liquid_cms_upgrade_rev1'
9
+ m.migration_template 'migration_rev2.rb', File.join('db', 'migrate'), :migration_file_name => 'create_liquid_cms_upgrade_rev2'
9
10
 
10
11
  # initializers
11
12
  m.directory File.join('config', 'initializers', 'cms')
@@ -39,6 +39,8 @@ en:
39
39
  index:
40
40
  title: 'Components'
41
41
  none: 'There are currently no components.'
42
+ flash:
43
+ updated: 'The component file has been updated.'
42
44
 
43
45
  simple_form:
44
46
  "yes": 'Yes'
@@ -68,6 +70,8 @@ en:
68
70
  content: 'To create a layout page, add the <em>{{ content_for_layout }}</em> tag which will act as a placeholder for the contents of another page. Use ctrl+s to save.'
69
71
  slug: 'The url path that will be used to access this page. Defaults to the page name if not provided. ie. /name.<br/> Ex. /home_page'
70
72
  layout_page_id: 'Optional page that will be used as this pages layout. Ie. This pages content will be inserted into the layout page where the <em>{{ content_for_layout }}</em> tag is specified.'
73
+ published: 'Make this page accessible via the pages name or url path?'
74
+ root: 'Make this page the sites root path (/)? Only one page can have this designation.'
71
75
  cms_component:
72
76
  file_content: '<em>No liquid support for editing components.</em> Use ctrl+s to save.'
73
77
  cms_asset:
@@ -0,0 +1,13 @@
1
+ class CreateLiquidCmsUpgradeRev2 < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :cms_assets do |t|
4
+ t.text :cms_asset_dimensions # serialized yaml
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ change_table :cms_assets do |t|
10
+ t.remove :cms_asset_dimensions
11
+ end
12
+ end
13
+ end
@@ -1,23 +1,19 @@
1
- Copyright (c) 2007-2010 Marijn Haverbeke
1
+ Copyright (C) 2011 by Marijn Haverbeke <marijnh@gmail.com>
2
2
 
3
- This software is provided 'as-is', without any express or implied
4
- warranty. In no event will the authors be held liable for any
5
- damages arising from the use of this software.
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
6
9
 
7
- Permission is granted to anyone to use this software for any
8
- purpose, including commercial applications, and to alter it and
9
- redistribute it freely, subject to the following restrictions:
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
10
12
 
11
- 1. The origin of this software must not be misrepresented; you must
12
- not claim that you wrote the original software. If you use this
13
- software in a product, an acknowledgment in the product
14
- documentation would be appreciated but is not required.
15
-
16
- 2. Altered source versions must be plainly marked as such, and must
17
- not be misrepresented as being the original software.
18
-
19
- 3. This notice may not be removed or altered from any source
20
- distribution.
21
-
22
- Marijn Haverbeke
23
- marijnh@gmail.com
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ .CodeMirror {
2
+ line-height: 1em;
3
+ font-family: monospace;
4
+ }
5
+
6
+ .CodeMirror-scroll {
7
+ overflow: auto;
8
+ height: 300px;
9
+ /* This is needed to prevent an IE[67] bug where the scrolled content
10
+ is visible outside of the scrolling box. */
11
+ position: relative;
12
+ }
13
+
14
+ .CodeMirror-gutter {
15
+ position: absolute; left: 0; top: 0;
16
+ z-index: 10;
17
+ background-color: #f7f7f7;
18
+ border-right: 1px solid #eee;
19
+ min-width: 2em;
20
+ height: 100%;
21
+ }
22
+ .CodeMirror-gutter-text {
23
+ color: #aaa;
24
+ text-align: right;
25
+ padding: .4em .2em .4em .4em;
26
+ }
27
+ .CodeMirror-lines {
28
+ padding: .4em;
29
+ }
30
+
31
+ .CodeMirror pre {
32
+ -moz-border-radius: 0;
33
+ -webkit-border-radius: 0;
34
+ -o-border-radius: 0;
35
+ border-radius: 0;
36
+ border-width: 0; margin: 0; padding: 0; background: transparent;
37
+ font-family: inherit;
38
+ font-size: inherit;
39
+ padding: 0; margin: 0;
40
+ white-space: pre;
41
+ word-wrap: normal;
42
+ }
43
+
44
+ .CodeMirror textarea {
45
+ font-family: inherit !important;
46
+ font-size: inherit !important;
47
+ }
48
+
49
+ .CodeMirror-cursor {
50
+ z-index: 10;
51
+ position: absolute;
52
+ visibility: hidden;
53
+ border-left: 1px solid black !important;
54
+ }
55
+ .CodeMirror-focused .CodeMirror-cursor {
56
+ visibility: visible;
57
+ }
58
+
59
+ span.CodeMirror-selected {
60
+ background: #ccc !important;
61
+ color: HighlightText !important;
62
+ }
63
+ .CodeMirror-focused span.CodeMirror-selected {
64
+ background: Highlight !important;
65
+ }
66
+
67
+ .CodeMirror-matchingbracket {color: #0f0 !important;}
68
+ .CodeMirror-nonmatchingbracket {color: #f22 !important;}