liquid_cms 0.3.1.0 → 0.3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/CHANGELOG.rdoc +10 -0
  2. data/Gemfile +0 -3
  3. data/README.rdoc +16 -2
  4. data/TODO.rdoc +0 -2
  5. data/app/controllers/cms/assets_controller.rb +20 -6
  6. data/app/controllers/cms/components_controller.rb +11 -3
  7. data/app/controllers/cms/pages_controller.rb +15 -4
  8. data/app/helpers/cms/common_helper.rb +31 -32
  9. data/app/liquid/cms_paperclip_extension.rb +75 -3
  10. data/app/liquid/tags/{data_tag.rb → cms/data_tag.rb} +0 -0
  11. data/app/models/cms/asset.rb +1 -1
  12. data/app/models/cms/component.rb +3 -3
  13. data/app/views/cms/assets/_form.html.erb +1 -2
  14. data/app/views/cms/assets/update.js.rjs +1 -0
  15. data/app/views/cms/components/update.js.rjs +1 -0
  16. data/app/views/cms/pages/_form.html.erb +3 -3
  17. data/app/views/cms/pages/update.js.rjs +1 -0
  18. data/app/views/layouts/cms.html.erb +4 -3
  19. data/config/initializers/cms/simple_form.rb +70 -12
  20. data/config/initializers/cms/simple_form_updates.rb +9 -3
  21. data/config/locales/cms/en.yml +6 -0
  22. data/lib/generators/liquid_cms/install_generator.rb +5 -1
  23. data/lib/generators/liquid_cms/templates/migration_rev2.rb +13 -0
  24. data/lib/generators/liquid_cms/templates/public/cms/codemirror/LICENSE +16 -20
  25. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.css +68 -0
  26. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.js +2197 -0
  27. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/overlay.js +51 -0
  28. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/runmode.js +27 -0
  29. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/clike.js +247 -0
  30. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/index.html +102 -0
  31. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/clojure.js +207 -0
  32. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/index.html +85 -0
  33. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/LICENSE +22 -0
  34. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/coffeescript.js +325 -0
  35. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/index.html +722 -0
  36. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/css/css.js +124 -0
  37. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/css/index.html +56 -0
  38. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.css +3 -0
  39. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.js +13 -0
  40. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/index.html +99 -0
  41. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/haskell.js +242 -0
  42. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/index.html +60 -0
  43. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/htmlmixed.js +79 -0
  44. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/index.html +52 -0
  45. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/index.html +78 -0
  46. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/javascript.js +352 -0
  47. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/index.html +38 -0
  48. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/jinja2.js +42 -0
  49. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/index.html +72 -0
  50. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/lua.js +140 -0
  51. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/index.html +340 -0
  52. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.css +10 -0
  53. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.js +230 -0
  54. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/index.html +33 -0
  55. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/ntriples.js +172 -0
  56. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/LICENSE +7 -0
  57. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/index.html +49 -0
  58. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/pascal.js +138 -0
  59. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/php/index.html +49 -0
  60. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/php/php.js +116 -0
  61. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/index.html +63 -0
  62. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/plsql.js +217 -0
  63. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/LICENSE.txt +21 -0
  64. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/index.html +123 -0
  65. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/python.js +320 -0
  66. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/LICENSE +24 -0
  67. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/index.html +74 -0
  68. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/r.js +141 -0
  69. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/index.html +526 -0
  70. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.css +75 -0
  71. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.js +333 -0
  72. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/LICENSE +24 -0
  73. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/index.html +172 -0
  74. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/ruby.js +195 -0
  75. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/index.html +65 -0
  76. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/scheme.js +202 -0
  77. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/index.html +56 -0
  78. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/smalltalk.js +122 -0
  79. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/index.html +41 -0
  80. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/sparql.js +143 -0
  81. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/index.html +96 -0
  82. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/stex.js +167 -0
  83. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/index.html +103 -0
  84. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/velocity.js +146 -0
  85. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/index.html +42 -0
  86. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/xml.js +231 -0
  87. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/index.html +60 -0
  88. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/xmlpure.js +481 -0
  89. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/index.html +68 -0
  90. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/yaml.js +95 -0
  91. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/cobalt.css +17 -0
  92. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/default.css +19 -0
  93. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/eclipse.css +24 -0
  94. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/elegant.css +9 -0
  95. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/neat.css +8 -0
  96. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/night.css +20 -0
  97. data/lib/generators/liquid_cms/templates/public/cms/javascripts/cms.js +1 -1
  98. data/lib/generators/liquid_cms/templates/public/cms/javascripts/codemirror_custom.js +96 -0
  99. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/codemirror_changes.css +26 -0
  100. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/liquid.css +7 -0
  101. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/simple_form.css +0 -8
  102. data/lib/liquid_cms/version.rb +1 -1
  103. data/liquid_cms.gemspec +1 -1
  104. data/test/functional/assets_controller_test.rb +35 -20
  105. data/test/functional/components_controller_test.rb +15 -5
  106. data/test/functional/pages_controller_test.rb +19 -6
  107. data/test/rails_app/Gemfile +1 -2
  108. data/test/rails_app/config/locales/cms/en.yml +26 -4
  109. data/test/rails_app/db/migrate/20110511161859_create_liquid_cms_upgrade_rev2.rb +13 -0
  110. data/test/unit/asset_test.rb +1 -1
  111. data/test/unit/component_test.rb +1 -1
  112. metadata +89 -32
  113. data/generators/liquid_cms/templates/migration_rev1.rb +0 -38
  114. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/csscolors.css +0 -55
  115. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/docs.css +0 -158
  116. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/font.js +0 -15
  117. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/jscolors.css +0 -59
  118. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/sparqlcolors.css +0 -43
  119. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/xmlcolors.css +0 -55
  120. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/codemirror.js +0 -582
  121. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/editor.js +0 -1671
  122. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/highlight.js +0 -68
  123. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/mirrorframe.js +0 -81
  124. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsecss.js +0 -161
  125. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsedummy.js +0 -32
  126. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsehtmlmixed.js +0 -93
  127. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsejavascript.js +0 -359
  128. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsesparql.js +0 -162
  129. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsexml.js +0 -291
  130. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/select.js +0 -699
  131. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/stringstream.js +0 -159
  132. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/tokenize.js +0 -57
  133. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/tokenizejavascript.js +0 -174
  134. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/undo.js +0 -413
  135. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/unittests.js +0 -44
  136. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/util.js +0 -133
@@ -1,3 +1,13 @@
1
+ == 0.3.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
+
8
+ * Fixes
9
+ * Move data_tag.rb file into cms dir due to possible rails class loading issues.
10
+
1
11
  == 0.3.1.0
2
12
 
3
13
  * Enhancements
data/Gemfile CHANGED
@@ -3,9 +3,6 @@ source :gemcutter
3
3
  # Specify your gem's dependencies in liquid_cms.gemspec
4
4
  gemspec
5
5
 
6
- # this version of vestal_versions is compatible with rails 3
7
- gem 'vestal_versions', '~> 1.2.1', :git => 'http://github.com/adamcooper/vestal_versions.git'
8
-
9
6
  group :test do
10
7
  gem 'shoulda', '~> 2.10.3'
11
8
  gem 'factory_girl', '~> 1.3.0'
@@ -14,7 +14,7 @@ See the {wiki page}[http://github.com/redlinesoftware/liquid_cms/wiki] for addit
14
14
 
15
15
  Add the gem to your Gemfile:
16
16
 
17
- gem 'liquid_cms', '~> 0.3.0'
17
+ gem 'liquid_cms', '~> 0.3.2'
18
18
 
19
19
  Install the gem:
20
20
 
@@ -33,7 +33,7 @@ The generator adds an additional dependency to your application, so bundler shou
33
33
  Configure the engine in config/initializers/cms/liquid_cms.rb:
34
34
 
35
35
  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:
36
-
36
+
37
37
  * Set the *context_class* attribute to your apps context class:
38
38
 
39
39
  config.context_class = :Company
@@ -62,6 +62,20 @@ In order to expose data in your application in the templates, liquid filters, dr
62
62
 
63
63
  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.
64
64
 
65
+ 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.
66
+
67
+ class Customer
68
+ has_attached :photo
69
+
70
+ def to_liquid
71
+ photo.to_liquid
72
+ end
73
+ end
74
+
75
+ change_table :customers do |t|
76
+ t.text :cms_photo_dimensions # field name must be named after the paperclip name. ie. :cms_{paperclip name}_dimensions
77
+ end
78
+
65
79
  = Upgrading
66
80
 
67
81
  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,49 +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 = <<-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
- js.html_safe
58
- end
57
+ javascript_tag %(initCodemirror('#{mode}', $$('#{form}').first(), $('#{content_id}'), #{use_ajax}, #{liquid_support}))
59
58
  end
60
59
 
61
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
@@ -23,10 +23,9 @@
23
23
 
24
24
  <div class="text required">
25
25
  <%= f.input :file_content, :as => :text, :input_html => {:rows => 40, :cols => nil} %>
26
- <span class="hint"><%= t('simple_form.hints.cms_asset.file_content').html_safe %></span>
27
26
  </div>
28
27
 
29
- <%= 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? %>
30
29
  <% end %>
31
30
 
32
31
  <div class="dimensions">
@@ -0,0 +1 @@
1
+ cms_ajax_update_form page, @asset, 'assets'
@@ -0,0 +1 @@
1
+ page << cms_flash_message
@@ -1,7 +1,7 @@
1
1
  <%= simple_form_for @page do |f| %>
2
- <%= f.input :name %>
2
+ <%= f.input :name, :required => true %>
3
3
  <%= f.input :slug, :required => false %>
4
- <%= f.input :content, :input_html => {:rows => 30, :spellcheck => false} %>
4
+ <%= f.input :content, :input_html => {:spellcheck => false} %>
5
5
  <%= f.input :layout_page_id, :collection => layouts_for_page(@page).collect{|pg| [pg.to_s, pg.id]}, :include_blank => '-- layout file --', :required => false unless layouts_for_page(@page).empty? %>
6
6
  <%= f.input :published, :required => false %>
7
7
  <%= f.input :root, :required => false %>
@@ -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', 'rails' %>
8
8
  <%= javascript_include_tag '/cms/javascripts/humanmsg', '/cms/javascripts/cookiejar', '/cms/javascripts/remote_helpers', '/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' %>
@@ -27,11 +28,11 @@
27
28
  <div id="outer-container" class="clearfix">
28
29
  <div id="sidebar" class="shadow curved">
29
30
  <%= render 'cms/shared/sidebar' %>
30
- </div>
31
+ </div>
31
32
 
32
33
  <div id="content">
33
34
  <%= yield %>
34
- <%= cms_flash_message %>
35
+ <%= load_cms_flash_message %>
35
36
  </div>
36
37
  </div>
37
38
  </body>