comfortable_mexican_sofa 1.9.1 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,8 +18,10 @@ Installation
18
18
  ------------
19
19
  Add gem definition to your Gemfile:
20
20
 
21
- gem 'comfortable_mexican_sofa', '~> 1.9.0'
22
-
21
+ ```ruby
22
+ gem 'comfortable_mexican_sofa', '~> 1.9.0'
23
+ ```
24
+
23
25
  Then from the Rails project's root run:
24
26
 
25
27
  bundle install
@@ -39,8 +41,10 @@ Installation for Rails 3
39
41
  ------------------------
40
42
  For Rails 3 apps feel free to use [1.8 release](https://github.com/comfy/comfortable-mexican-sofa/tree/1.8)
41
43
 
42
- gem 'comfortable_mexican_sofa', '~> 1.8.0'
43
-
44
+ ```ruby
45
+ gem 'comfortable_mexican_sofa', '~> 1.8.0'
46
+ ```
47
+
44
48
  Quick Start Guide
45
49
  -----------------
46
50
  After finishing installation you should be able to navigate to http://yoursite/cms-admin
@@ -1,4 +1,4 @@
1
- class CmsAdmin::BaseController < ApplicationController
1
+ class CmsAdmin::BaseController < ComfortableMexicanSofa.config.base_controller.to_s.constantize
2
2
 
3
3
  protect_from_forgery
4
4
 
@@ -13,7 +13,7 @@ class CmsAdmin::SnippetsController < CmsAdmin::BaseController
13
13
  end
14
14
 
15
15
  def edit
16
- render
16
+ @snippet.attributes = snippet_params
17
17
  end
18
18
 
19
19
  def create
@@ -4,35 +4,38 @@ ComfortableMexicanSofa.configure do |config|
4
4
  # Title of the admin area
5
5
  # config.cms_title = 'ComfortableMexicanSofa CMS Engine'
6
6
 
7
+ # Controller that is inherited from CmsAdmin::BaseController
8
+ # config.base_controller = 'ApplicationController'
9
+
7
10
  # Module responsible for authentication. You can replace it with your own.
8
11
  # It simply needs to have #authenticate method. See http_auth.rb for reference.
9
12
  # config.admin_auth = 'ComfortableMexicanSofa::HttpAuth'
10
-
13
+
11
14
  # Module responsible for public authentication. Similar to the above. You also
12
15
  # will have access to @cms_site, @cms_layout, @cms_page so you can use them in
13
16
  # your logic. Default module doesn't do anything.
14
17
  # config.public_auth = 'ComfortableMexicanSofa::DummyAuth'
15
-
18
+
16
19
  # When arriving at /cms-admin you may chose to redirect to arbirtary path,
17
20
  # for example '/cms-admin/users'
18
21
  # config.admin_route_redirect = ''
19
-
22
+
20
23
  # File uploads use Paperclip and can support filesystem or s3 uploads. Override
21
24
  # the upload method and appropriate settings based on Paperclip. For S3 see:
22
- # http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/S3, and for
25
+ # http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/S3, and for
23
26
  # filesystem see: http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/Filesystem
24
27
  # If you are using S3 and HTTPS, pass :s3_protocol => '' to have URLs that use the protocol of the page
25
28
  # config.upload_file_options = {:url => '/system/:class/:id/:attachment/:style/:filename'}
26
-
29
+
27
30
  # Sofa allows you to setup entire site from files. Database is updated with each
28
31
  # request (if necessary). Please note that database entries are destroyed if there's
29
32
  # no corresponding file. Fixtures are disabled by default.
30
33
  # config.enable_fixtures = false
31
-
34
+
32
35
  # Path where fixtures can be located.
33
36
  # config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
34
-
35
- # Importing fixtures into Database
37
+
38
+ # Importing fixtures into Database
36
39
  # To load fixtures into the database just run this rake task:
37
40
  # local: $ rake comfortable_mexican_sofa:fixtures:import FROM=example.local TO=localhost
38
41
  # Heroku: $ heroku run rake comfortable_mexican_sofa:fixtures:import FROM=example.local TO=yourapp.herokuapp.com
@@ -43,16 +46,16 @@ ComfortableMexicanSofa.configure do |config|
43
46
  # local: $ rake comfortable_mexican_sofa:fixtures:export FROM=localhost TO=example.local
44
47
  # Heroku: $ heroku run rake comfortable_mexican_sofa:fixtures:export FROM=yourapp.herokuapp.com TO=example.local
45
48
  # This will create example.local folder and dump all content from example.com Site.
46
-
49
+
47
50
  # Content for Layouts, Pages and Snippets has a revision history. You can revert
48
51
  # a previous version using this system. You can control how many revisions per
49
52
  # object you want to keep. Set it to 0 if you wish to turn this feature off.
50
53
  # config.revisions_limit = 25
51
-
54
+
52
55
  # Locale definitions. If you want to define your own locale merge
53
56
  # {:locale => 'Locale Title'} with this.
54
57
  # config.locales = {:en => 'English', :es => 'Español'}
55
-
58
+
56
59
  # Admin interface will respect the locale of the site being managed. However you can
57
60
  # force it to English by setting this to `:en`
58
61
  # config.admin_locale = nil
@@ -61,30 +64,30 @@ ComfortableMexicanSofa.configure do |config|
61
64
  # add a database_config. For example, setting it to 'cms' will look for a cms_#{Rails.env}
62
65
  # definition in your database.yml file
63
66
  # config.database_config = nil
64
-
67
+
65
68
  # A class that is included as a sweeper to admin base controller if it's set
66
69
  # config.admin_cache_sweeper = nil
67
-
70
+
68
71
  # By default you cannot have irb code inside your layouts/pages/snippets.
69
72
  # Generally this is to prevent putting something like this:
70
73
  # <% User.delete_all %> but if you really want to allow it...
71
74
  # config.allow_irb = false
72
-
75
+
73
76
  # Whitelist of all helper methods that can be used via {{cms:helper}} tag. By default
74
77
  # all helpers are allowed except `eval`, `send`, `call` and few others. Empty array
75
78
  # will prevent rendering of all helpers.
76
79
  # config.allowed_helpers = nil
77
-
80
+
78
81
  # Whitelist of partials paths that can be used via {{cms:partial}} tag. All partials
79
82
  # are accessible by default. Empty array will prevent rendering of all partials.
80
83
  # config.allowed_partials = nil
81
-
82
- # Site aliases, if you want to have aliases for your site. Good for harmonizing
84
+
85
+ # Site aliases, if you want to have aliases for your site. Good for harmonizing
83
86
  # production env with dev/testing envs.
84
87
  # e.g. config.hostname_aliases = {'host.com' => 'host.inv', 'host_a.com' => ['host.lvh.me', 'host.dev']}
85
88
  # Default is nil (not used)
86
89
  # config.hostname_aliases = nil
87
-
90
+
88
91
  end
89
92
 
90
93
  # Default credentials for ComfortableMexicanSofa::HttpAuth
@@ -4,6 +4,10 @@ class ComfortableMexicanSofa::Configuration
4
4
 
5
5
  # Don't like ComfortableMexicanSofa? Set it to whatever you like. :(
6
6
  attr_accessor :cms_title
7
+
8
+ # Controller that is inherited from CmsAdmin::BaseController
9
+ # 'ApplicationController' is the default
10
+ attr_accessor :base_controller
7
11
 
8
12
  # Module that will handle authentication to access cms-admin area
9
13
  attr_accessor :admin_auth
@@ -57,6 +61,10 @@ class ComfortableMexicanSofa::Configuration
57
61
  # are accessible by default. Empty array will prevent rendering of all partials.
58
62
  attr_accessor :allowed_partials
59
63
 
64
+ # Whitelist of template paths that can be used via {{cms:template}} tag. All templates
65
+ # are accessible by default. Empty array will prevent rendering of all templates.
66
+ attr_accessor :allowed_templates
67
+
60
68
  # Site aliases, if you want to have aliases for your site. Good for harmonizing
61
69
  # production env with dev/testing envs.
62
70
  # e.g. config.site_aliases = {'host.com' => 'host.inv', 'host_a.com' => ['host.lvh.me', 'host.dev']}
@@ -66,6 +74,7 @@ class ComfortableMexicanSofa::Configuration
66
74
  # Configuration defaults
67
75
  def initialize
68
76
  @cms_title = 'ComfortableMexicanSofa CMS Engine'
77
+ @base_controller = 'ApplicationController'
69
78
  @admin_auth = 'ComfortableMexicanSofa::HttpAuth'
70
79
  @public_auth = 'ComfortableMexicanSofa::DummyAuth'
71
80
  @seed_data_path = nil
@@ -57,7 +57,7 @@ module ComfortableMexicanSofa::Fixture::Page
57
57
  page.blocks_attributes = blocks_attributes if blocks_attributes.present?
58
58
 
59
59
  # saving
60
- if page.changed? || self.force_import
60
+ if page.changed? || page.blocks_attributes_changed || self.force_import
61
61
  if page.save
62
62
  save_categorizations!(page, categories)
63
63
  ComfortableMexicanSofa.logger.warn("[FIXTURES] Imported Page \t #{page.full_path}")
@@ -119,4 +119,4 @@ module ComfortableMexicanSofa::Fixture::Page
119
119
  end
120
120
  end
121
121
  end
122
- end
122
+ end
@@ -0,0 +1,22 @@
1
+ class ComfortableMexicanSofa::Tag::Template
2
+ include ComfortableMexicanSofa::Tag
3
+
4
+ def self.regex_tag_signature(identifier = nil)
5
+ identifier ||= /[\w\/\-]+/
6
+ /\{\{\s*cms:template:(#{identifier})\s*\}\}/
7
+ end
8
+
9
+ def content
10
+ "<%= render :template => '#{identifier}' %>"
11
+ end
12
+
13
+ def render
14
+ whitelist = ComfortableMexicanSofa.config.allowed_templates
15
+ if whitelist.is_a?(Array)
16
+ content if whitelist.member?(identifier)
17
+ else
18
+ content
19
+ end
20
+ end
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  module ComfortableMexicanSofa
2
- VERSION = "1.9.1"
2
+ VERSION = "1.9.2"
3
3
  end
@@ -1,34 +1,66 @@
1
1
  module ComfortableMexicanSofa::ViewMethods
2
-
2
+
3
3
  # Wrapper around ComfortableMexicanSofa::FormBuilder
4
4
  def comfy_form_for(record, options = {}, &proc)
5
5
  options[:builder] = ComfortableMexicanSofa::FormBuilder
6
6
  options[:type] ||= :horizontal
7
7
  formatted_form_for(record, options, &proc)
8
8
  end
9
-
9
+
10
10
  # Injects some content somewhere inside cms admin area
11
11
  def cms_hook(name, options = {})
12
12
  ComfortableMexicanSofa::ViewHooks.render(name, self, options)
13
13
  end
14
14
 
15
- # Content of a snippet. Example:
15
+ # Content of a snippet. Examples:
16
16
  # cms_snippet_content(:my_snippet)
17
- def cms_snippet_content(identifier, cms_site = nil)
17
+ # <%= cms_snippet_content(:my_snippet) do %>
18
+ # Default content can go here.
19
+ # <% end %>
20
+ def cms_snippet_content(identifier, cms_site = nil, &block)
18
21
  unless cms_site
19
22
  host, path = request.host.downcase, request.fullpath if respond_to?(:request) && request
20
23
  cms_site ||= (@cms_site || Cms::Site.find_site(host, path))
21
24
  end
22
- return '' unless cms_site
23
- case identifier
24
- when Cms::Snippet
25
- snippet = identifier
26
- else
27
- return '' unless snippet = cms_site.snippets.find_by_identifier(identifier)
25
+ return '' unless cms_site && identifier.present?
26
+ snippet = cms_site.snippets.find_by_identifier(identifier)
27
+
28
+ if !snippet && block_given?
29
+ snippet = cms_site.snippets.create(
30
+ :identifier => identifier,
31
+ :label => identifier.to_s.titleize,
32
+ :content => capture(&block)
33
+ )
28
34
  end
29
35
  render :inline => ComfortableMexicanSofa::Tag.process_content(cms_site.pages.build, snippet.content)
30
36
  end
31
-
37
+
38
+ # Content of a text based page block. This is the typical method for retrieving content from
39
+ # page:field. Note: This method will be faster than the more generic cms_page_content.
40
+ #
41
+ # Example:
42
+ # cms_page_block_content(:left_column, CmsPage.first)
43
+ # cms_page_block_content(:left_column) if @cms_page is present
44
+ def cms_page_block_content(identifier, page = nil)
45
+ return '' unless page ||= @cms_page
46
+ return '' unless block = page.blocks.find_by_identifier(identifier)
47
+
48
+ ComfortableMexicanSofa::Tag.process_content(page, block.content)
49
+ end
50
+
51
+ # Fetch files from a page:field. Will return a list of files, regardless of how many files are present.
52
+ # Note: This method will be faster than the more generic cms_page_content.
53
+ #
54
+ # Example:
55
+ # cms_page_block_content(:open_graph_image, CmsPage.first)
56
+ # cms_page_block_content(:attachments, CmsPage.first)
57
+ def cms_page_files(identifier, page = nil)
58
+ return nil unless page ||= @cms_page
59
+ return nil unless block = page.blocks.find_by_identifier(identifier)
60
+
61
+ block.files
62
+ end
63
+
32
64
  # Content of a page block. This is how you get content from page:field
33
65
  # Example:
34
66
  # cms_page_content(:left_column, CmsPage.first)
@@ -52,6 +52,14 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
52
52
  assert_template :edit
53
53
  assert_select "form[action=/cms-admin/sites/#{snippet.site.id}/snippets/#{snippet.id}]"
54
54
  end
55
+
56
+ def test_get_edit_with_params
57
+ snippet = cms_snippets(:default)
58
+ get :edit, :site_id => snippet.site, :id => snippet, :snippet => {:label => 'New Label'}
59
+ assert_response :success
60
+ assert assigns(:snippet)
61
+ assert_equal 'New Label', assigns(:snippet).label
62
+ end
55
63
 
56
64
  def test_get_edit_failure
57
65
  get :edit, :site_id => cms_sites(:default), :id => 'not_found'
@@ -7,6 +7,7 @@ class ConfigurationTest < ActiveSupport::TestCase
7
7
  def test_configuration_presence
8
8
  assert config = ComfortableMexicanSofa.configuration
9
9
  assert_equal 'ComfortableMexicanSofa CMS Engine', config.cms_title
10
+ assert_equal 'ApplicationController', config.base_controller
10
11
  assert_equal 'ComfortableMexicanSofa::HttpAuth', config.admin_auth
11
12
  assert_equal 'ComfortableMexicanSofa::DummyAuth', config.public_auth
12
13
  assert_equal '', config.admin_route_redirect
@@ -0,0 +1,56 @@
1
+ require_relative '../../test_helper'
2
+
3
+ class TemplateTagTest < ActiveSupport::TestCase
4
+
5
+ def test_initialize_tag
6
+ assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
7
+ cms_pages(:default), '{{ cms:template:template_name }}'
8
+ )
9
+ assert_equal 'template_name', tag.identifier
10
+ assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
11
+ cms_pages(:default), '{{cms:template:path/to/template}}'
12
+ )
13
+ assert_equal 'path/to/template', tag.identifier
14
+ assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
15
+ cms_pages(:default), '{{cms:template:path/to/dashed-template}}'
16
+ )
17
+ assert_equal 'path/to/dashed-template', tag.identifier
18
+ end
19
+
20
+ def test_initialize_tag_failure
21
+ [
22
+ '{{cms:template}}',
23
+ '{{cms:not_template:label}}',
24
+ '{not_a_tag}'
25
+ ].each do |tag_signature|
26
+ assert_nil ComfortableMexicanSofa::Tag::Template.initialize_tag(
27
+ cms_pages(:default), tag_signature
28
+ )
29
+ end
30
+ end
31
+
32
+ def test_content_and_render
33
+ tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
34
+ cms_pages(:default), '{{cms:template:path/to/template}}'
35
+ )
36
+ assert_equal "<%= render :template => 'path/to/template' %>", tag.content
37
+ assert_equal "<%= render :template => 'path/to/template' %>", tag.render
38
+ end
39
+
40
+ def test_whitelisted_paths
41
+ ComfortableMexicanSofa.config.allowed_templates = ['safe/path']
42
+
43
+ tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
44
+ cms_pages(:default), '{{cms:template:safe/path}}'
45
+ )
46
+ assert_equal "<%= render :template => 'safe/path' %>", tag.content
47
+ assert_equal "<%= render :template => 'safe/path' %>", tag.render
48
+
49
+ tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
50
+ cms_pages(:default), '{{cms:template:unsafe/path}}'
51
+ )
52
+ assert_equal "<%= render :template => 'unsafe/path' %>", tag.content
53
+ assert_equal nil, tag.render
54
+ end
55
+
56
+ end
@@ -1,9 +1,9 @@
1
1
  require_relative '../test_helper'
2
2
 
3
3
  class ViewMethodsTest < ActionView::TestCase
4
-
4
+
5
5
  include ComfortableMexicanSofa::ViewMethods
6
-
6
+
7
7
  class ::HelpersTestController < ActionController::Base
8
8
  helper { def hello; 'hello' end }
9
9
 
@@ -11,6 +11,17 @@ class ViewMethodsTest < ActionView::TestCase
11
11
  render :inline => '<%= cms_snippet_content(:default) %>'
12
12
  end
13
13
 
14
+ def test_cms_page_block_content
15
+ @cms_page = Cms::Page.root
16
+ render :inline => '<%= cms_page_block_content(:default_field_text) %>'
17
+ end
18
+
19
+ def test_cms_snippet_with_default_content_block
20
+ render :inline => '<%= cms_snippet_content(:nonexistent_snippet) do %>
21
+ Some content <b>here</b>.
22
+ <% end %>'
23
+ end
24
+
14
25
  def test_cms_page_content
15
26
  @cms_page = Cms::Page.root
16
27
  render :inline => '<%= cms_page_content(:default_field_text) %>'
@@ -24,7 +35,7 @@ class ViewMethodsTest < ActionView::TestCase
24
35
  end
25
36
  end
26
37
  end
27
-
38
+
28
39
  # Simulating a call and getting resulting output
29
40
  def action_result(action)
30
41
  HelpersTestController.action(action).call(ActionController::TestRequest.new.env).last.body
@@ -41,26 +52,64 @@ class ViewMethodsTest < ActionView::TestCase
41
52
  def test_cms_snippet_content
42
53
  assert_equal 'default_snippet_content', action_result('test_cms_snippet_content')
43
54
  end
44
-
55
+
45
56
  def test_cms_snippet_content_with_tags
46
57
  cms_snippets(:default).update_columns(:content => '{{cms:helper:hello}}')
47
58
  assert_equal 'hello', action_result('test_cms_snippet_content')
48
59
  end
49
-
60
+
50
61
  def test_cms_snippet_content_with_file_tag
51
62
  cms_snippets(:default).update_column(:content, '{{cms:file:sample.jpg}}')
52
63
  assert_equal cms_files(:default).file.url, action_result('test_cms_snippet_content')
53
64
  end
65
+
66
+ def test_cms_page_block_content
67
+ assert_equal 'default_field_text_content', action_result('test_cms_page_block_content')
68
+ end
69
+
70
+ def test_cms_page_files
71
+ page = cms_pages(:default)
72
+ page.layout.update_column(:content, '{{cms:page_files:files}}')
73
+ page.update_attributes!(
74
+ :blocks_attributes => [
75
+ {
76
+ :identifier => 'files',
77
+ :content => [
78
+ fixture_file_upload('files/image.jpg', "image/jpeg"),
79
+ fixture_file_upload('files/image.gif', "image/gif")
80
+ ]
81
+ }
82
+ ]
83
+ )
84
+ assert_equal page.blocks.find_by_identifier('files').files, cms_page_files(:files, page)
85
+ end
86
+
87
+ def test_cms_snippet_with_default_content_block_displays_content
88
+ assert_equal 'Some content <b>here</b>.',
89
+ action_result('test_cms_snippet_with_default_content_block').strip
90
+ end
91
+
92
+ def test_cms_snippet_with_default_content_creates_snippet
93
+ assert_nil Cms::Snippet.find_by_identifier('nonexistent_snippet')
94
+ action_result('test_cms_snippet_with_default_content_block')
95
+ assert_not_nil Cms::Snippet.find_by_identifier('nonexistent_snippet')
96
+ end
97
+
98
+ def test_cms_snippet_with_default_content_shows_stored_snippet_if_present
99
+ cms_snippets(:default).update_attribute(:identifier, 'nonexistent_snippet')
100
+ assert_equal 'default_snippet_content',
101
+ action_result('test_cms_snippet_with_default_content_block')
102
+ end
54
103
 
55
104
  def test_cms_page_content
56
105
  assert_equal 'default_field_text_content', action_result('test_cms_page_content')
57
106
  end
58
-
107
+
59
108
  def test_cms_page_content_with_tags
60
109
  cms_blocks(:default_field_text).update_column(:content, '{{cms:helper:hello}}')
61
110
  assert_equal 'hello', action_result('test_cms_page_content')
62
111
  end
63
-
112
+
64
113
  def test_cms_page_content_with_files
65
114
  page = cms_pages(:default)
66
115
  page.layout.update_column(:content, '{{cms:page_file:file}} {{cms:page_files:files}}')
@@ -76,5 +125,5 @@ class ViewMethodsTest < ActionView::TestCase
76
125
  assert_equal page.blocks.find_by_identifier('file').files.first, cms_page_content(:file, page)
77
126
  assert_equal page.blocks.find_by_identifier('files').files, cms_page_content(:files, page)
78
127
  end
79
-
80
- end
128
+
129
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-13 00:00:00.000000000 Z
13
+ date: 2013-09-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -375,6 +375,7 @@ files:
375
375
  - lib/comfortable_mexican_sofa/tags/page_text.rb
376
376
  - lib/comfortable_mexican_sofa/tags/partial.rb
377
377
  - lib/comfortable_mexican_sofa/tags/snippet.rb
378
+ - lib/comfortable_mexican_sofa/tags/template.rb
378
379
  - lib/comfortable_mexican_sofa/version.rb
379
380
  - lib/comfortable_mexican_sofa/view_hooks.rb
380
381
  - lib/comfortable_mexican_sofa/view_methods.rb
@@ -453,6 +454,7 @@ files:
453
454
  - test/models/tags/page_text_test.rb
454
455
  - test/models/tags/partial_test.rb
455
456
  - test/models/tags/snippet_test.rb
457
+ - test/models/tags/template_test.rb
456
458
  - test/models/view_methods_test.rb
457
459
  - test/test_helper.rb
458
460
  homepage: http://github.com/comfy/comfortable-mexican-sofa