comfortable_mexican_sofa 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '>=3.0.0'
3
+ gem 'rails', '>=3.0.1'
4
4
  gem 'sqlite3-ruby', :require => 'sqlite3'
5
5
  gem 'active_link_to', '>=0.0.6'
6
6
  gem 'paperclip', '>=2.3.3'
data/Gemfile.lock CHANGED
@@ -2,12 +2,12 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  abstract (1.0.0)
5
- actionmailer (3.0.0)
6
- actionpack (= 3.0.0)
5
+ actionmailer (3.0.1)
6
+ actionpack (= 3.0.1)
7
7
  mail (~> 2.2.5)
8
- actionpack (3.0.0)
9
- activemodel (= 3.0.0)
10
- activesupport (= 3.0.0)
8
+ actionpack (3.0.1)
9
+ activemodel (= 3.0.1)
10
+ activesupport (= 3.0.1)
11
11
  builder (~> 2.1.2)
12
12
  erubis (~> 2.6.6)
13
13
  i18n (~> 0.4.1)
@@ -16,26 +16,25 @@ GEM
16
16
  rack-test (~> 0.5.4)
17
17
  tzinfo (~> 0.3.23)
18
18
  active_link_to (0.0.6)
19
- activemodel (3.0.0)
20
- activesupport (= 3.0.0)
19
+ activemodel (3.0.1)
20
+ activesupport (= 3.0.1)
21
21
  builder (~> 2.1.2)
22
22
  i18n (~> 0.4.1)
23
- activerecord (3.0.0)
24
- activemodel (= 3.0.0)
25
- activesupport (= 3.0.0)
23
+ activerecord (3.0.1)
24
+ activemodel (= 3.0.1)
25
+ activesupport (= 3.0.1)
26
26
  arel (~> 1.0.0)
27
27
  tzinfo (~> 0.3.23)
28
- activeresource (3.0.0)
29
- activemodel (= 3.0.0)
30
- activesupport (= 3.0.0)
31
- activesupport (3.0.0)
28
+ activeresource (3.0.1)
29
+ activemodel (= 3.0.1)
30
+ activesupport (= 3.0.1)
31
+ activesupport (3.0.1)
32
32
  arel (1.0.1)
33
33
  activesupport (~> 3.0.0)
34
34
  builder (2.1.2)
35
35
  erubis (2.6.6)
36
36
  abstract (>= 1.0.0)
37
- gemcutter (0.5.0)
38
- json_pure
37
+ gemcutter (0.6.1)
39
38
  git (1.2.5)
40
39
  i18n (0.4.1)
41
40
  jeweler (1.4.0)
@@ -43,38 +42,38 @@ GEM
43
42
  git (>= 1.2.5)
44
43
  rubyforge (>= 2.0.0)
45
44
  json_pure (1.4.6)
46
- mail (2.2.5)
45
+ mail (2.2.7)
47
46
  activesupport (>= 2.3.6)
48
47
  mime-types
49
48
  treetop (>= 1.4.5)
50
49
  mime-types (1.16)
51
- paperclip (2.3.3)
50
+ paperclip (2.3.4)
52
51
  activerecord
53
52
  activesupport
54
53
  polyglot (0.3.1)
55
54
  rack (1.2.1)
56
55
  rack-mount (0.6.13)
57
56
  rack (>= 1.0.0)
58
- rack-test (0.5.4)
57
+ rack-test (0.5.6)
59
58
  rack (>= 1.0)
60
- rails (3.0.0)
61
- actionmailer (= 3.0.0)
62
- actionpack (= 3.0.0)
63
- activerecord (= 3.0.0)
64
- activeresource (= 3.0.0)
65
- activesupport (= 3.0.0)
59
+ rails (3.0.1)
60
+ actionmailer (= 3.0.1)
61
+ actionpack (= 3.0.1)
62
+ activerecord (= 3.0.1)
63
+ activeresource (= 3.0.1)
64
+ activesupport (= 3.0.1)
66
65
  bundler (~> 1.0.0)
67
- railties (= 3.0.0)
68
- railties (3.0.0)
69
- actionpack (= 3.0.0)
70
- activesupport (= 3.0.0)
66
+ railties (= 3.0.1)
67
+ railties (3.0.1)
68
+ actionpack (= 3.0.1)
69
+ activesupport (= 3.0.1)
71
70
  rake (>= 0.8.4)
72
71
  thor (~> 0.14.0)
73
72
  rake (0.8.7)
74
73
  rubyforge (2.0.4)
75
74
  json_pure (>= 1.1.7)
76
75
  sqlite3-ruby (1.3.1)
77
- thor (0.14.0)
76
+ thor (0.14.3)
78
77
  treetop (1.4.8)
79
78
  polyglot (>= 0.3.1)
80
79
  tzinfo (0.3.23)
@@ -87,5 +86,5 @@ DEPENDENCIES
87
86
  jeweler (>= 1.4.0)
88
87
  mime-types
89
88
  paperclip (>= 2.3.3)
90
- rails (>= 3.0.0)
89
+ rails (>= 3.0.1)
91
90
  sqlite3-ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -1,7 +1,6 @@
1
- # Authentication module must have #authenticate method
2
- include ComfortableMexicanSofa.config.authentication.to_s.constantize
3
-
4
1
  class CmsAdmin::BaseController < ApplicationController
2
+ # Authentication module must have #authenticate method
3
+ include ComfortableMexicanSofa.config.authentication.to_s.constantize
5
4
 
6
5
  before_filter :authenticate,
7
6
  :load_admin_cms_site
@@ -26,7 +26,12 @@ protected
26
26
  end
27
27
 
28
28
  def load_cms_page
29
- @cms_page = @cms_site.cms_pages.find_by_full_path!("/#{params[:cms_path]}")
29
+ # Attempting to load seed page
30
+ if ComfortableMexicanSofa.configuration.seed_data_path
31
+ @cms_page = CmsPage.load_from_file(@cms_site, "/#{params[:cms_path]}")
32
+ end
33
+
34
+ @cms_page ||= @cms_site.cms_pages.find_by_full_path!("/#{params[:cms_path]}")
30
35
  return redirect_to(@cms_page.target_page.full_path) if @cms_page.target_page
31
36
  rescue ActiveRecord::RecordNotFound
32
37
  if @cms_page = @cms_site.cms_pages.find_by_full_path('/404')
@@ -7,9 +7,16 @@ class CmsLayout < ActiveRecord::Base
7
7
  has_many :cms_pages, :dependent => :nullify
8
8
 
9
9
  # -- Validations ----------------------------------------------------------
10
- validates :cms_site_id, :presence => true
11
- validates :label, :presence => true
12
- validates :content, :presence => true
10
+ validates :cms_site_id,
11
+ :presence => true
12
+ validates :label,
13
+ :presence => true
14
+ validates :slug,
15
+ :presence => true,
16
+ :uniqueness => { :scope => :cms_site_id },
17
+ :format => { :with => /^\w[a-z0-9_-]*$/i }
18
+ validates :content,
19
+ :presence => true
13
20
 
14
21
  # -- Class Methods --------------------------------------------------------
15
22
  # Tree-like structure for layouts
@@ -33,6 +40,17 @@ class CmsLayout < ActiveRecord::Base
33
40
  end.compact
34
41
  end
35
42
 
43
+ # Attempting to initialize layout object from yaml file that is found in config.seed_data_path
44
+ def self.load_from_file(site, name)
45
+ return nil if ComfortableMexicanSofa.config.seed_data_path.blank?
46
+ file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/layouts/#{name}.yml"
47
+ return nil unless File.exists?(file_path)
48
+ attributes = YAML.load_file(file_path).symbolize_keys!
49
+ attributes[:parent] = CmsLayout.load_from_file(site, attributes[:parent])
50
+ attributes[:cms_site] = site
51
+ new(attributes)
52
+ end
53
+
36
54
  # -- Instance Methods -----------------------------------------------------
37
55
  # magical merging tag is <cms:page:content> If parent layout has this tag
38
56
  # defined its content will be merged. If no such tag found, parent content
@@ -47,10 +65,10 @@ class CmsLayout < ActiveRecord::Base
47
65
  end
48
66
 
49
67
  def merged_css
50
- self.parent ? self.parent.merged_css + self.css : self.css.to_s
68
+ self.parent ? [self.parent.merged_css, self.css].join("\n") : self.css.to_s
51
69
  end
52
70
 
53
71
  def merged_js
54
- self.parent ? self.parent.merged_js + self.js : self.js.to_s
72
+ self.parent ? [self.parent.merged_js, self.js].join("\n") : self.js.to_s
55
73
  end
56
74
  end
@@ -45,6 +45,20 @@ class CmsPage < ActiveRecord::Base
45
45
  return out.compact
46
46
  end
47
47
 
48
+ # Attempting to initialize page object from yaml file that is found in config.seed_data_path
49
+ # This file defines all attributes of the page plus all the block information
50
+ def self.load_from_file(site, url)
51
+ return nil if ComfortableMexicanSofa.config.seed_data_path.blank?
52
+ url = (url == '/')? '/index' : url.to_s.chomp('/')
53
+ file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/pages#{url}.yml"
54
+ return nil unless File.exists?(file_path)
55
+ attributes = YAML.load_file(file_path).symbolize_keys!
56
+ attributes[:cms_layout] = CmsLayout.load_from_file(site, attributes[:cms_layout])
57
+ attributes[:parent] = CmsPage.load_from_file(site, attributes[:parent])
58
+ attributes[:cms_site] = site
59
+ new(attributes)
60
+ end
61
+
48
62
  # -- Instance Methods -----------------------------------------------------
49
63
  # Processing content will return rendered content and will populate
50
64
  # self.cms_tags with instances of CmsTag
@@ -19,7 +19,19 @@ class CmsSnippet < ActiveRecord::Base
19
19
  end
20
20
 
21
21
  def self.initialize_or_find(cms_page, slug)
22
- find_by_slug(slug) || new(:slug => slug)
22
+ if ComfortableMexicanSofa.configuration.seed_data_path
23
+ s = CmsTag::Snippet.load_from_file(cms_page.cms_site, slug)
24
+ end
25
+ s || find_by_slug(slug) || new(:slug => slug)
26
+ end
27
+
28
+ # Attempting to initialize snippet object from yaml file that is found in config.seed_data_path
29
+ def self.load_from_file(site, name)
30
+ return nil if ComfortableMexicanSofa.config.seed_data_path.blank?
31
+ file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/snippets/#{name}.yml"
32
+ return nil unless File.exists?(file_path)
33
+ attributes = YAML.load_file(file_path).symbolize_keys!
34
+ new(attributes)
23
35
  end
24
36
 
25
37
  end
@@ -1,4 +1,5 @@
1
- <%= form.text_field :label, :label => 'Layout Name' %>
1
+ <%= form.text_field :label, :label => 'Layout Name', :id => (@cms_layout.new_record?? 'slugify' : nil)%>
2
+ <%= form.text_field :slug, :id => 'slug' %>
2
3
  <%= form.select :parent_id, CmsLayout.options_for_select(@cms_site, @cms_layout), :include_blank => true %>
3
4
  <%= form.select :app_layout, CmsLayout.app_layouts_for_select, :include_blank => true %>
4
5
  <%= form.text_area :content %>
@@ -14,6 +14,9 @@
14
14
  </div>
15
15
  <div class='label'>
16
16
  <%= link_to cms_layout.label, edit_cms_admin_layout_path(cms_layout) %>
17
+ <div class='sublabel'>
18
+ <%= link_to cms_layout.slug, edit_cms_admin_layout_path(cms_layout) %>
19
+ </div>
17
20
  </div>
18
21
  </div>
19
22
  <% if cms_layout.children.present? %>
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{comfortable_mexican_sofa}
8
- s.version = "1.0.2"
8
+ s.version = "1.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oleg Khabarov", "The Working Group Inc"]
12
- s.date = %q{2010-10-19}
12
+ s.date = %q{2010-10-25}
13
13
  s.description = %q{}
14
14
  s.email = %q{oleg@theworkinggroup.ca}
15
15
  s.extra_rdoc_files = [
@@ -85,6 +85,7 @@ Gem::Specification.new do |s|
85
85
  "lib/comfortable_mexican_sofa/cms_tag/field_integer.rb",
86
86
  "lib/comfortable_mexican_sofa/cms_tag/field_string.rb",
87
87
  "lib/comfortable_mexican_sofa/cms_tag/field_text.rb",
88
+ "lib/comfortable_mexican_sofa/cms_tag/helper.rb",
88
89
  "lib/comfortable_mexican_sofa/cms_tag/page_datetime.rb",
89
90
  "lib/comfortable_mexican_sofa/cms_tag/page_integer.rb",
90
91
  "lib/comfortable_mexican_sofa/cms_tag/page_string.rb",
@@ -120,7 +121,12 @@ Gem::Specification.new do |s|
120
121
  "public/stylesheets/comfortable_mexican_sofa/structure.css",
121
122
  "public/stylesheets/comfortable_mexican_sofa/typography.css",
122
123
  "script/rails",
123
- "test/fixtures/README.md",
124
+ "test/cms_seeds/test.host/layouts/default.yml",
125
+ "test/cms_seeds/test.host/layouts/nested.yml",
126
+ "test/cms_seeds/test.host/pages/child.yml",
127
+ "test/cms_seeds/test.host/pages/child/subchild.yml",
128
+ "test/cms_seeds/test.host/pages/index.yml",
129
+ "test/cms_seeds/test.host/snippets/default.yml",
124
130
  "test/fixtures/cms_blocks.yml",
125
131
  "test/fixtures/cms_layouts.yml",
126
132
  "test/fixtures/cms_pages.yml",
@@ -136,6 +142,7 @@ Gem::Specification.new do |s|
136
142
  "test/functional/cms_admin/uploads_controller_test.rb",
137
143
  "test/functional/cms_content_controller_test.rb",
138
144
  "test/integration/authentication_test.rb",
145
+ "test/integration/render_cms_seed_test.rb",
139
146
  "test/integration/render_cms_test.rb",
140
147
  "test/integration/sites_test.rb",
141
148
  "test/test_helper.rb",
@@ -150,14 +157,14 @@ Gem::Specification.new do |s|
150
157
  "test/unit/cms_tags/field_integer_test.rb",
151
158
  "test/unit/cms_tags/field_string_test.rb",
152
159
  "test/unit/cms_tags/field_text_test.rb",
160
+ "test/unit/cms_tags/helper_test.rb",
153
161
  "test/unit/cms_tags/page_datetime_test.rb",
154
162
  "test/unit/cms_tags/page_integer_test.rb",
155
163
  "test/unit/cms_tags/page_string_test.rb",
156
164
  "test/unit/cms_tags/page_text_test.rb",
157
165
  "test/unit/cms_tags/partial_test.rb",
158
166
  "test/unit/cms_tags/snippet_test.rb",
159
- "test/unit/cms_upload_test.rb",
160
- "tmp/restart.txt"
167
+ "test/unit/cms_upload_test.rb"
161
168
  ]
162
169
  s.homepage = %q{http://github.com/theworkinggroup/comfortable-mexican-sofa}
163
170
  s.rdoc_options = ["--charset=UTF-8"]
@@ -172,6 +179,7 @@ Gem::Specification.new do |s|
172
179
  "test/functional/cms_admin/uploads_controller_test.rb",
173
180
  "test/functional/cms_content_controller_test.rb",
174
181
  "test/integration/authentication_test.rb",
182
+ "test/integration/render_cms_seed_test.rb",
175
183
  "test/integration/render_cms_test.rb",
176
184
  "test/integration/sites_test.rb",
177
185
  "test/test_helper.rb",
@@ -186,6 +194,7 @@ Gem::Specification.new do |s|
186
194
  "test/unit/cms_tags/field_integer_test.rb",
187
195
  "test/unit/cms_tags/field_string_test.rb",
188
196
  "test/unit/cms_tags/field_text_test.rb",
197
+ "test/unit/cms_tags/helper_test.rb",
189
198
  "test/unit/cms_tags/page_datetime_test.rb",
190
199
  "test/unit/cms_tags/page_integer_test.rb",
191
200
  "test/unit/cms_tags/page_string_test.rb",
data/config/routes.rb CHANGED
@@ -14,9 +14,9 @@ Rails.application.routes.draw do
14
14
  end
15
15
 
16
16
  scope :controller => :cms_content do
17
- get '/cms-css/:id' => :render_css, :format => 'css'
18
- get '/cms-js/:id' => :render_js, :format => 'js'
19
- get '/' => :render_html, :path => '(*cms_path)'
17
+ get '/cms-css/:id' => :render_css, :as => 'cms_css', :format => 'css'
18
+ get '/cms-js/:id' => :render_js, :as => 'cms_js', :format => 'js'
19
+ get '/' => :render_html, :as => 'cms_html', :path => '(*cms_path)'
20
20
  end
21
21
 
22
22
  end
@@ -14,14 +14,15 @@ class CreateCms < ActiveRecord::Migration
14
14
  t.integer :parent_id
15
15
  t.string :app_layout
16
16
  t.string :label
17
+ t.string :slug
17
18
  t.text :content
18
19
  t.text :css
19
20
  t.text :js
20
21
  t.integer :position, :null => false, :default => 0
21
22
  t.timestamps
22
23
  end
23
- add_index :cms_layouts, [:cms_site_id, :label]
24
24
  add_index :cms_layouts, [:parent_id, :position]
25
+ add_index :cms_layouts, [:cms_site_id, :slug], :unique => true
25
26
 
26
27
  # -- Pages --------------------------------------------------------------
27
28
  create_table :cms_pages do |t|
@@ -0,0 +1,20 @@
1
+ class CmsTag::Helper
2
+
3
+ attr_accessor :label
4
+
5
+ include CmsTag
6
+
7
+ def self.regex_tag_signature(label = nil)
8
+ label ||= /\w+/
9
+ /<\s*cms:helper:(#{label})\s*\/?>/
10
+ end
11
+
12
+ def regex_tag_signature
13
+ self.class.regex_tag_signature(label)
14
+ end
15
+
16
+ def content
17
+ "<%= #{label} %>"
18
+ end
19
+
20
+ end
@@ -6,14 +6,15 @@ class ComfortableMexicanSofa::Configuration
6
6
  # Module that will handle authentication to access cms-admin area
7
7
  attr_accessor :authentication
8
8
 
9
- # Enable cms to manage multiple sites
10
- attr_accessor :multiple_sites
9
+ # Location of YAML files that can be used to render pages instead of pulling
10
+ # data from the database. Not active if not specified.
11
+ attr_accessor :seed_data_path
11
12
 
12
13
  # Configuration defaults
13
14
  def initialize
14
- @cms_title = 'ComfortableMexicanSofa'
15
- @authentication = 'CmsHttpAuthentication'
16
- @multiple_sites = false
15
+ @cms_title = 'ComfortableMexicanSofa'
16
+ @authentication = 'ComfortableMexicanSofa::HttpAuth'
17
+ @seed_data_path = nil
17
18
  end
18
19
 
19
20
  end
@@ -1,12 +1,17 @@
1
- ____ __ _ _ _
2
- / ___|___ _ __ ___ / _| ___ _ __| |_ __ _| |__ | | ___
3
- | | / _ \| '_ ` _ \| |_ / _ \| '__| __/ _` | '_ \| |/ _ \
4
- | |__| (_) | | | | | | _| (_) | | | || (_| | |_) | | __/
5
- \____\___/|_| |_| |_|_| \___/|_| \__\__,_|_.__/|_|\___|
6
- __ __ _ ____ __
7
- | \/ | _____ _(_) ___ __ _ _ __ / ___| ___ / _| __ _
8
- | |\/| |/ _ \ \/ / |/ __/ _` | '_ \ \___ \ / _ \| |_ / _` |
9
- | | | | __/> <| | (_| (_| | | | | ___) | (_) | _| (_| |
10
- |_| |_|\___/_/\_\_|\___\__,_|_| |_| |____/ \___/|_| \__,_|
1
+ ____ __ _ _ _
2
+ / ___|___ _ __ ___ / _| ___ _ __| |_ __ _| |__ | | ___
3
+ | | / _ \| '_ ` _ \| |_ / _ \| '__| __/ _` | '_ \| |/ _ \
4
+ | |__| (_) | | | | | | _| (_) | | | || (_| | |_) | | __/
5
+ \____\___/|_| |_| |_|_| \___/|_| \__\__,_|_.__/|_|\___|
6
+ __ __ _ ____ __
7
+ | \/ | _____ _(_) ___ __ _ _ __ / ___| ___ / _| __ _
8
+ | |\/| |/ _ \ \/ / |/ __/ _` | '_ \ \___ \ / _ \| |_ / _` |
9
+ | | | | __/> <| | (_| (_| | | | | ___) | (_) | _| (_| |
10
+ |_| |_|\___/_/\_\_|\___\__,_|_| |_| |____/ \___/|_| \__,_|
11
11
 
12
- Hey, thanks for being AWESOME!
12
+ Hey! Everything is almost done. Please don't forget to
13
+
14
+ * run migrations -> `rake db:migrate`
15
+
16
+ After that go to http://your-awesome-app/cms-admin to start
17
+ populating content.
@@ -0,0 +1,2 @@
1
+ label: Default Layout
2
+ content: <html><cms:page:content/></html>
@@ -0,0 +1,3 @@
1
+ label: Nested Layout
2
+ parent: default
3
+ content: <div><cms:page:content/></div>
@@ -0,0 +1,10 @@
1
+ label: Child Page
2
+ parent: /
3
+ cms_layout: default
4
+ slug: child
5
+ cms_blocks_attributes:
6
+ -
7
+ label: content
8
+ type: CmsTag::PageText
9
+ content: |-
10
+ Child Page Content
@@ -0,0 +1,10 @@
1
+ label: Child Page
2
+ parent: /child
3
+ cms_layout: nested
4
+ slug: subchild
5
+ cms_blocks_attributes:
6
+ -
7
+ label: content
8
+ type: CmsTag::PageText
9
+ content: |-
10
+ Sub Child Page Content <cms:snippet:default/>
@@ -0,0 +1,10 @@
1
+ label: Default Page
2
+ parent:
3
+ cms_layout: default
4
+ slug:
5
+ cms_blocks_attributes:
6
+ -
7
+ label: content
8
+ type: CmsTag::PageText
9
+ content: |-
10
+ Default Page Content
@@ -0,0 +1,3 @@
1
+ label: Default Snippet
2
+ slug: default
3
+ content: Content for Default Snippet
@@ -1,6 +1,7 @@
1
1
  default:
2
2
  cms_site: default
3
3
  label: Default Layout
4
+ slug: default
4
5
  parent:
5
6
  content: |-
6
7
  <cms:field:default_field_text:text>
@@ -9,39 +10,27 @@ default:
9
10
  layout_content_b
10
11
  <cms:snippet:default>
11
12
  layout_content_c
12
- css: |-
13
- body { background-color: red }
14
- p { color: #fff }
15
- js: |-
16
- $(document).ready(function() {
17
- alert('hi');
18
- })
13
+ css: default_css
14
+ js: default_js
19
15
 
20
16
  nested:
21
17
  cms_site: default
22
18
  label: Nested Layout
19
+ slug: nested
23
20
  parent:
24
21
  content: |-
25
22
  <cms:page:header/>
26
23
  <cms:page:content/>
27
- css: |-
28
- body { background-color: red }
29
- js: |-
30
- $(document).ready(function() {
31
- alert('hi');
32
- })
24
+ css: nested_css
25
+ js: nested_js
33
26
 
34
27
  child:
35
28
  cms_site: default
36
29
  label: Child Layout
30
+ slug: child
37
31
  parent: nested
38
32
  content: |-
39
33
  <cms:page:left_column>
40
34
  <cms:page:right_column>
41
- css: |-
42
- body { p: #fff }
43
- js: |-
44
- js: |-
45
- $(document).ready(function() {
46
- alert('sup');
47
- })
35
+ css: child_css
36
+ js: child_js
@@ -37,6 +37,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
37
37
  assert_difference 'CmsLayout.count' do
38
38
  post :create, :cms_layout => {
39
39
  :label => 'Test Layout',
40
+ :slug => 'test',
40
41
  :content => 'Test Content'
41
42
  }
42
43
  assert_response :redirect
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RenderCmsSeedTest < ActionDispatch::IntegrationTest
4
+
5
+ def test_render_with_seed_data_enabled
6
+ get '/child/subchild'
7
+ assert_response 404
8
+
9
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
10
+
11
+ get '/child/subchild'
12
+ assert_response :success
13
+ assert_equal '<html><div>Sub Child Page Content Content for Default Snippet</div></html>', response.body
14
+ end
15
+
16
+ end
data/test/test_helper.rb CHANGED
@@ -11,6 +11,7 @@ class ActiveSupport::TestCase
11
11
  ComfortableMexicanSofa.configure do |config|
12
12
  config.cms_title = 'ComfortableMexicanSofa'
13
13
  config.authentication = 'ComfortableMexicanSofa::HttpAuth'
14
+ config.seed_data_path = nil
14
15
  end
15
16
  ComfortableMexicanSofa::HttpAuth.username = 'username'
16
17
  ComfortableMexicanSofa::HttpAuth.password = 'password'
@@ -6,6 +6,7 @@ class CmsConfigurationTest < ActiveSupport::TestCase
6
6
  assert config = ComfortableMexicanSofa.configuration
7
7
  assert_equal 'ComfortableMexicanSofa', config.cms_title
8
8
  assert_equal 'ComfortableMexicanSofa::HttpAuth', config.authentication
9
+ assert_equal nil, config.seed_data_path
9
10
  end
10
11
 
11
12
  def test_initialization_overrides
@@ -11,13 +11,16 @@ class CmsLayoutTest < ActiveSupport::TestCase
11
11
  def test_validations
12
12
  layout = CmsLayout.create
13
13
  assert layout.errors.present?
14
- assert_has_errors_on layout, [:label, :content]
14
+ assert_has_errors_on layout, [:label, :slug, :content]
15
15
  end
16
16
 
17
17
  def test_options_for_select
18
- assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'], CmsLayout.options_for_select(cms_sites(:default)).collect{|t| t.first}
19
- assert_equal ['Default Layout', 'Nested Layout'], CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:child)).collect{|t| t.first}
20
- assert_equal ['Default Layout'], CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:nested)).collect{|t| t.first}
18
+ assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'],
19
+ CmsLayout.options_for_select(cms_sites(:default)).collect{|t| t.first}
20
+ assert_equal ['Default Layout', 'Nested Layout'],
21
+ CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:child)).collect{|t| t.first}
22
+ assert_equal ['Default Layout'],
23
+ CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:nested)).collect{|t| t.first}
21
24
  end
22
25
 
23
26
  def test_app_layouts_for_select
@@ -36,13 +39,28 @@ class CmsLayoutTest < ActiveSupport::TestCase
36
39
  end
37
40
 
38
41
  def test_merged_css
39
- merged_css = cms_layouts(:nested).css + cms_layouts(:child).css
40
- assert_equal merged_css, cms_layouts(:child).merged_css
42
+ assert_equal "nested_css\nchild_css", cms_layouts(:child).merged_css
41
43
  end
42
44
 
43
45
  def test_merged_js
44
- merged_js = cms_layouts(:nested).js + cms_layouts(:child).js
45
- assert_equal merged_js, cms_layouts(:child).merged_js
46
+ assert_equal "nested_js\nchild_js", cms_layouts(:child).merged_js
47
+ end
48
+
49
+ def test_load_from_file
50
+ assert !CmsLayout.load_from_file(cms_sites(:default), 'default')
51
+
52
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
53
+
54
+ assert !CmsLayout.load_from_file(cms_sites(:default), 'bogus')
55
+
56
+ assert layout = CmsLayout.load_from_file(cms_sites(:default), 'default')
57
+ assert_equal 'Default Layout', layout.label
58
+ assert_equal '<html><cms:page:content/></html>', layout.content
59
+
60
+ assert layout = CmsLayout.load_from_file(cms_sites(:default), 'nested')
61
+ assert_equal 'Nested Layout', layout.label
62
+ assert_equal '<div><cms:page:content/></div>', layout.content
63
+ assert_equal '<html><div><cms:page:content/></div></html>', layout.merged_content
46
64
  end
47
65
 
48
66
  end
@@ -112,12 +112,41 @@ class CmsPageTest < ActiveSupport::TestCase
112
112
  end
113
113
 
114
114
  def test_options_for_select
115
- assert_equal ['Default Page', '. . Child Page'], CmsPage.options_for_select(cms_sites(:default)).collect{|t| t.first }
116
- assert_equal ['Default Page'], CmsPage.options_for_select(cms_sites(:default), cms_pages(:child)).collect{|t| t.first }
117
- assert_equal [], CmsPage.options_for_select(cms_sites(:default), cms_pages(:default))
115
+ assert_equal ['Default Page', '. . Child Page'],
116
+ CmsPage.options_for_select(cms_sites(:default)).collect{|t| t.first }
117
+ assert_equal ['Default Page'],
118
+ CmsPage.options_for_select(cms_sites(:default), cms_pages(:child)).collect{|t| t.first }
119
+ assert_equal [],
120
+ CmsPage.options_for_select(cms_sites(:default), cms_pages(:default))
118
121
 
119
122
  page = CmsPage.new(new_params(:parent => cms_pages(:default)))
120
- assert_equal ['Default Page', '. . Child Page'], CmsPage.options_for_select(cms_sites(:default), page).collect{|t| t.first }
123
+ assert_equal ['Default Page', '. . Child Page'],
124
+ CmsPage.options_for_select(cms_sites(:default), page).collect{|t| t.first }
125
+ end
126
+
127
+ def test_load_from_file
128
+ assert !CmsPage.load_from_file(cms_sites(:default), '/')
129
+
130
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
131
+
132
+ assert !CmsPage.load_from_file(cms_sites(:default), '/bogus')
133
+
134
+ assert page = CmsPage.load_from_file(cms_sites(:default), '/')
135
+ assert_equal 'Default Page', page.label
136
+ assert_equal 1, page.cms_blocks.size
137
+ assert page.cms_layout
138
+ assert_equal '<html>Default Page Content</html>', page.content
139
+
140
+ assert page = CmsPage.load_from_file(cms_sites(:default), '/child')
141
+ assert_equal 1, page.cms_blocks.size
142
+ assert page.cms_layout
143
+ assert_equal '<html>Child Page Content</html>', page.content
144
+
145
+ assert page = CmsPage.load_from_file(cms_sites(:default), '/child/subchild')
146
+ assert_equal 1, page.cms_blocks.size
147
+ assert page.cms_layout
148
+ assert_equal 'Nested Layout', page.cms_layout.label
149
+ assert_equal '<html><div>Sub Child Page Content Content for Default Snippet</div></html>', page.content
121
150
  end
122
151
 
123
152
  protected
@@ -20,4 +20,16 @@ class CmsSnippetTest < ActiveSupport::TestCase
20
20
  assert_equal '', CmsSnippet.content_for('nonexistent_snippet')
21
21
  end
22
22
 
23
+ def test_load_from_file
24
+ assert !CmsSnippet.load_from_file(cms_sites(:default), 'default')
25
+
26
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
27
+
28
+ assert !CmsSnippet.load_from_file(cms_sites(:default), 'bogus')
29
+
30
+ assert snippet = CmsSnippet.load_from_file(cms_sites(:default), 'default')
31
+ assert_equal 'Default Snippet', snippet.label
32
+ assert_equal 'Content for Default Snippet', snippet.content
33
+ end
34
+
23
35
  end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class HelperTest < ActiveSupport::TestCase
4
+
5
+ def test_initialize_tag
6
+ %w(
7
+ <cms:helper:method_name/>
8
+ ).each do |tag_signature|
9
+ assert tag = CmsTag::Helper.initialize_tag(cms_pages(:default), tag_signature)
10
+ end
11
+ end
12
+
13
+ def test_initialize_tag_failure
14
+ %w(
15
+ <cms:helper>
16
+ <cms:not_helper:method_name/>
17
+ not_a_tag
18
+ ).each do |tag_signature|
19
+ assert_nil CmsTag::Helper.initialize_tag(cms_pages(:default), tag_signature)
20
+ end
21
+ end
22
+
23
+ def test_content_and_render
24
+ tag = CmsTag::Helper.initialize_tag(cms_pages(:default), "<cms:helper:method_name/>")
25
+ assert_equal "<%= method_name %>", tag.content
26
+ assert_equal "<%= method_name %>", tag.render
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oleg Khabarov
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-19 00:00:00 -04:00
19
+ date: 2010-10-25 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -145,6 +145,7 @@ files:
145
145
  - lib/comfortable_mexican_sofa/cms_tag/field_integer.rb
146
146
  - lib/comfortable_mexican_sofa/cms_tag/field_string.rb
147
147
  - lib/comfortable_mexican_sofa/cms_tag/field_text.rb
148
+ - lib/comfortable_mexican_sofa/cms_tag/helper.rb
148
149
  - lib/comfortable_mexican_sofa/cms_tag/page_datetime.rb
149
150
  - lib/comfortable_mexican_sofa/cms_tag/page_integer.rb
150
151
  - lib/comfortable_mexican_sofa/cms_tag/page_string.rb
@@ -180,7 +181,12 @@ files:
180
181
  - public/stylesheets/comfortable_mexican_sofa/structure.css
181
182
  - public/stylesheets/comfortable_mexican_sofa/typography.css
182
183
  - script/rails
183
- - test/fixtures/README.md
184
+ - test/cms_seeds/test.host/layouts/default.yml
185
+ - test/cms_seeds/test.host/layouts/nested.yml
186
+ - test/cms_seeds/test.host/pages/child.yml
187
+ - test/cms_seeds/test.host/pages/child/subchild.yml
188
+ - test/cms_seeds/test.host/pages/index.yml
189
+ - test/cms_seeds/test.host/snippets/default.yml
184
190
  - test/fixtures/cms_blocks.yml
185
191
  - test/fixtures/cms_layouts.yml
186
192
  - test/fixtures/cms_pages.yml
@@ -196,6 +202,7 @@ files:
196
202
  - test/functional/cms_admin/uploads_controller_test.rb
197
203
  - test/functional/cms_content_controller_test.rb
198
204
  - test/integration/authentication_test.rb
205
+ - test/integration/render_cms_seed_test.rb
199
206
  - test/integration/render_cms_test.rb
200
207
  - test/integration/sites_test.rb
201
208
  - test/test_helper.rb
@@ -210,6 +217,7 @@ files:
210
217
  - test/unit/cms_tags/field_integer_test.rb
211
218
  - test/unit/cms_tags/field_string_test.rb
212
219
  - test/unit/cms_tags/field_text_test.rb
220
+ - test/unit/cms_tags/helper_test.rb
213
221
  - test/unit/cms_tags/page_datetime_test.rb
214
222
  - test/unit/cms_tags/page_integer_test.rb
215
223
  - test/unit/cms_tags/page_string_test.rb
@@ -217,7 +225,6 @@ files:
217
225
  - test/unit/cms_tags/partial_test.rb
218
226
  - test/unit/cms_tags/snippet_test.rb
219
227
  - test/unit/cms_upload_test.rb
220
- - tmp/restart.txt
221
228
  has_rdoc: true
222
229
  homepage: http://github.com/theworkinggroup/comfortable-mexican-sofa
223
230
  licenses: []
@@ -260,6 +267,7 @@ test_files:
260
267
  - test/functional/cms_admin/uploads_controller_test.rb
261
268
  - test/functional/cms_content_controller_test.rb
262
269
  - test/integration/authentication_test.rb
270
+ - test/integration/render_cms_seed_test.rb
263
271
  - test/integration/render_cms_test.rb
264
272
  - test/integration/sites_test.rb
265
273
  - test/test_helper.rb
@@ -274,6 +282,7 @@ test_files:
274
282
  - test/unit/cms_tags/field_integer_test.rb
275
283
  - test/unit/cms_tags/field_string_test.rb
276
284
  - test/unit/cms_tags/field_text_test.rb
285
+ - test/unit/cms_tags/helper_test.rb
277
286
  - test/unit/cms_tags/page_datetime_test.rb
278
287
  - test/unit/cms_tags/page_integer_test.rb
279
288
  - test/unit/cms_tags/page_string_test.rb
@@ -1,22 +0,0 @@
1
- Default Test Application Data Structure
2
- =======================================
3
- Layout
4
- ------
5
- <cms:field:default_field:text>
6
- layout_content_a
7
- <cms:page:default_page:text>
8
- layout_content_b
9
- <cms:snippet:default_snippet>
10
- layout_content_c
11
- Page
12
- ----
13
- ### CmsBlock::FieldText
14
- default_field_content
15
- ### CmsBlock::PageText
16
- default_page_content_a
17
- <cms:snippet:default_snippet>
18
- default_page_content_a
19
- Snippets
20
- -------
21
- ### Snippet
22
- default_snippet_content