radiant-layouts-extension 0.9.1 → 1.0.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 (39) hide show
  1. data/MIT-LICENSE +75 -4
  2. data/README.md +48 -1
  3. data/Rakefile +56 -15
  4. data/VERSION +1 -1
  5. data/app/models/haml_filter.rb +5 -0
  6. data/app/views/layouts/radiant.html.haml +1 -1
  7. data/config/routes.rb +5 -0
  8. data/layouts_extension.rb +13 -5
  9. data/lib/haml_layouts/models/layout.rb +34 -0
  10. data/lib/haml_layouts/models/page.rb +31 -0
  11. data/lib/nested_layouts/tags/core.rb +141 -0
  12. data/lib/share_layouts/controllers/action_controller.rb +25 -0
  13. data/lib/share_layouts/helpers/action_view.rb +50 -0
  14. data/lib/tasks/layouts_extension_tasks.rake +27 -6
  15. data/radiant-layouts-extension.gemspec +37 -26
  16. data/spec/controllers/{share_layouts_spec.rb → share_controller_spec.rb} +0 -0
  17. data/spec/datasets/layouts_layouts.rb +36 -0
  18. data/spec/datasets/layouts_pages.rb +43 -0
  19. data/spec/lib/haml_layouts/haml_layouts_extension_spec.rb +22 -0
  20. data/spec/lib/haml_layouts/models/layout_spec.rb +36 -0
  21. data/spec/lib/haml_layouts/models/page_spec.rb +40 -0
  22. data/spec/lib/nested_layouts/nested_layouts_extension_spec.rb +16 -0
  23. data/spec/lib/nested_layouts/{tags_spec.rb → tags/core_spec.rb} +41 -17
  24. data/spec/{controllers/nested_layouts_spec.rb → lib/share_layouts/controllers/action_controller_spec.rb} +0 -1
  25. data/spec/{helpers/share_layouts_helper_spec.rb → lib/share_layouts/helpers/action_view_spec.rb} +32 -29
  26. data/spec/lib/share_layouts/share_layouts_extension_spec.rb +22 -0
  27. data/spec/models/haml_filter_spec.rb +0 -0
  28. data/spec/models/rails_page_spec.rb +9 -9
  29. data/spec/spec.opts +2 -3
  30. metadata +43 -28
  31. data/lib/nested_layouts.rb +0 -2
  32. data/lib/nested_layouts/tags.rb +0 -127
  33. data/lib/share_layouts.rb +0 -2
  34. data/lib/share_layouts/helper.rb +0 -39
  35. data/lib/share_layouts/radiant_layouts.rb +0 -21
  36. data/spec/datasets/nested_layouts_dataset.rb +0 -38
  37. data/spec/datasets/share_layouts_dataset.rb +0 -38
  38. data/spec/lib/share_layouts_extension_spec.rb +0 -25
  39. data/spec/rcov.opts +0 -2
@@ -12,7 +12,6 @@ describe ControllerWithRadiantLayout do
12
12
  dataset :layouts
13
13
 
14
14
  before(:each) do
15
- #layouts(:radiant)
16
15
  layouts(:main)
17
16
  end
18
17
 
@@ -1,17 +1,19 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
- describe ShareLayouts::Helper do
4
- include ShareLayouts::Helper
5
- dataset :layouts, :pages, :share_layouts
3
+ describe ShareLayouts::Helpers::ActionView do
4
+ include ShareLayouts::Helpers::ActionView
5
+
6
+ dataset :layouts_layouts, :layouts_pages
6
7
  test_helper :page
7
8
  attr_accessor :request, :response
8
-
9
- MAIN_RESULT = <<-TEXT
9
+
10
+ MAIN_RESULT = <<-TEXT
11
+ <!DOCTYPE html>
10
12
  <html>
11
13
  <head>
12
- <title>My Title</title>
14
+ <title>Title</title>
13
15
  </head>
14
- <body>
16
+ <body class="site parent">
15
17
  something
16
18
  </body>
17
19
  </html>
@@ -20,45 +22,45 @@ TEXT
20
22
  before(:each) do
21
23
  @page = RailsPage.new(page_params(:class_name => "RailsPage"))
22
24
  @content_for_layout = "something"
23
- @radiant_layout = layouts(:main).name
25
+ @radiant_layout = layouts(:parent).name
24
26
  @request = OpenStruct.new(:path => "/some/page/")
25
27
  end
26
-
28
+
27
29
  it "should extract_content_captures_as_hash" do
28
30
  extract_captures.should == {:body => "something"}
29
31
  @content_for_sidebar = "sidebar"
30
32
  extract_captures.should == {:body => "something", :sidebar => "sidebar"}
31
33
  end
32
-
34
+
33
35
  # testing assignment of layout
34
36
  it "should assign_layout_of_page" do
35
37
  assign_attributes!(@page)
36
- @page.layout.should == layouts(:main)
38
+ @page.layout.should == layouts(:parent)
37
39
  end
38
-
40
+
39
41
  it "should assign_layout_of_page_when_missing" do
40
42
  previous_layout = @page.layout
41
43
  @radiant_layout = ''
42
44
  assign_attributes!(@page)
43
45
  previous_layout.should == @page.layout
44
46
  end
45
-
47
+
46
48
  # testing assignment of page.title
47
49
  it "should assign_page_title_from_instance_var" do
48
50
  @title = "My title"
49
51
  assign_attributes!(@page)
50
52
  @page.title.should == "My title"
51
53
  end
52
-
54
+
53
55
  it "should assign_page_title_from_capture" do
54
56
  @content_for_title = "My title"
55
57
  assign_attributes!(@page)
56
58
  @page.title.should == "My title"
57
59
  end
58
-
60
+
59
61
  it "should assign_title_from_existing_page_title_when_not_specified" do
60
62
  assign_attributes!(@page)
61
- @page.title.should =~ /Page \d+$/ # was 'New Page' before. I assume this changed in Radiant 0.8
63
+ @page.title.should =~ /New Page/ # was 'New Page' before. I assume this changed in Radiant 0.8
62
64
  end
63
65
 
64
66
  it "should assign_empty_title_if_missing" do
@@ -69,20 +71,20 @@ TEXT
69
71
  assign_attributes!(@page)
70
72
  @page.title.should == ''
71
73
  end
72
-
74
+
73
75
  #testing assignment of page.breadcrumb
74
76
  it "should assign_page_breadcrumb_from_instance_var" do
75
77
  @breadcrumb = "My breadcrumb"
76
78
  assign_attributes!(@page)
77
79
  @page.breadcrumb.should == "My breadcrumb"
78
80
  end
79
-
81
+
80
82
  it "should assign_page_breadcrumb_from_capture" do
81
83
  @content_for_breadcrumb = "My breadcrumb"
82
84
  assign_attributes!(@page)
83
85
  @page.breadcrumb.should == "My breadcrumb"
84
86
  end
85
-
87
+
86
88
  it "should assign_breadcrumb_from_existing_breadcrumb_when_not_specified" do
87
89
  @page.breadcrumb = "existing breadcrumb"
88
90
  assign_attributes!(@page)
@@ -98,7 +100,7 @@ TEXT
98
100
  assign_attributes!(@page)
99
101
  @page.breadcrumb.should == 'Title into BC'
100
102
  end
101
-
103
+
102
104
  it "should assign_empty_breadcrumb_if_title_missing_too" do
103
105
  @page.title = nil
104
106
  @title.should be_nil
@@ -111,14 +113,14 @@ TEXT
111
113
  assign_attributes!(@page)
112
114
  @page.breadcrumb.should == ''
113
115
  end
114
-
116
+
115
117
  # testing assignment of page.breadcrumbs
116
118
  it "should assign_breadcrumbs_from_instance_var" do
117
119
  @breadcrumbs = "bc"
118
120
  assign_attributes!(@page)
119
121
  @page.breadcrumbs.should == 'bc'
120
122
  end
121
-
123
+
122
124
  it "should assign_breadcrumbs_from_capture" do
123
125
  @content_for_breadcrumbs = "bc"
124
126
  assign_attributes!(@page)
@@ -139,30 +141,31 @@ TEXT
139
141
  assign_attributes!(@page)
140
142
  @page.url.should == '/some/page/'
141
143
  end
142
-
144
+
143
145
  # testing assigment of page.slug
144
146
  it "should assign_slug_from_request_path" do
145
147
  assign_attributes!(@page)
146
148
  @page.slug.should == 'page'
147
149
  end
148
-
150
+
149
151
  # testing assignment of page.published_at
150
152
  it "should assign_published_at" do
151
153
  assign_attributes!(@page)
152
154
  @page.published_at.should_not be_nil
153
155
  end
154
-
156
+
155
157
  it "should render_page" do
156
158
  @title = "My Title"
157
159
  radiant_layout.strip.should == MAIN_RESULT.strip
158
160
  end
159
-
161
+
160
162
  it "should find_page" do
161
163
  @request.path = "/app/something/"
162
- find_page.should == pages(:rails_page)
164
+ find_page.should == pages(:rails)
163
165
  find_page.should be_a_kind_of(RailsPage)
164
166
  @request.path = "/some-other/url/"
165
- find_page.should_not == pages(:rails_page)
167
+ find_page.should_not == pages(:rails)
166
168
  find_page.should be_a_kind_of(RailsPage)
167
169
  end
168
- end
170
+
171
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec/spec_helper'
2
+
3
+ # Ensures that the Extension initializes correctly
4
+ describe LayoutsExtension do
5
+
6
+ context 'activate' do
7
+
8
+ describe 'share layouts' do
9
+ it 'should have a RailsPage class to call' do
10
+ RailsPage.should_not be_nil
11
+ end
12
+ it 'should extend ActionController base methods' do
13
+ ActionController::Base.included_modules.include?(ShareLayouts::Controllers::ActionController).should be_true
14
+ end
15
+ it 'should extend ActionView helper methods' do
16
+ ActionView::Base.included_modules.include?(ShareLayouts::Helpers::ActionView).should be_true
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
File without changes
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
 
4
4
  describe RailsPage do
5
5
  test_helper :render, :page
6
- dataset :share_layouts, :pages
6
+ dataset :layouts_layouts, :layouts_pages
7
7
 
8
8
  before(:each) do
9
9
  @page = RailsPage.new(page_params(:class_name => "RailsPage"))
@@ -18,9 +18,9 @@ describe RailsPage do
18
18
  end
19
19
 
20
20
  it "should use_old_breadcrumbs_tag_if_breadcrumbs_attr_is_nil" do
21
- @page = pages(:rails_page)
21
+ @page = pages(:rails)
22
22
  @page.breadcrumbs = nil
23
- @page.should render("<r:breadcrumbs nolinks='true' />").as("Homepage &gt; App page")
23
+ @page.should render("<r:breadcrumbs nolinks='true' />").as("parent &gt; App page")
24
24
  end
25
25
 
26
26
  it "should build_parts_from_hash" do
@@ -32,13 +32,13 @@ describe RailsPage do
32
32
  end
33
33
 
34
34
  it "should find_rails_page_for_sub_urls_that_do_not_match_an_existing_page" do
35
- Page.find_by_url('/app/').should == pages(:rails_page)
36
- Page.find_by_url('/app/some-other-url/').should == pages(:rails_page)
37
- Page.find_by_url('/app/some-other-url/sub-url/').should == pages(:rails_page)
35
+ Page.find_by_url('/app/').should == pages(:rails)
36
+ Page.find_by_url('/app/some-other-url/').should == pages(:rails)
37
+ Page.find_by_url('/app/some-other-url/sub-url/').should == pages(:rails)
38
38
  end
39
39
 
40
40
  it "should find_page_if_sub_url_matches_one" do
41
- Page.find_by_url('/app/child-page/').should == pages(:rails_page_child)
41
+ Page.find_by_url('/app/child-page/').should == pages(:rails_child)
42
42
  end
43
43
 
44
44
  it "should find_page_for_non_sub_urls" do
@@ -46,11 +46,11 @@ describe RailsPage do
46
46
  end
47
47
 
48
48
  it "should defer_to_default_url_when_not_initialized" do
49
- pages(:rails_page).url.should == '/app/'
49
+ pages(:rails).url.should == '/app/'
50
50
  end
51
51
 
52
52
  it "should modify_existing_parts_but_not_save_them" do
53
- @page = pages(:rails_page)
53
+ @page = pages(:rails)
54
54
  @page.parts.create(:name => "sidebar", :content => "This is the sidebar.")
55
55
 
56
56
  @page.build_parts_from_hash!(:body => "This is the body")
data/spec/spec.opts CHANGED
@@ -1,4 +1,3 @@
1
1
  --colour
2
- --format progress
3
- --loadby mtime
4
- --reverse
2
+ --format specdoc
3
+ --loadby mtime
metadata CHANGED
@@ -1,21 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-layouts-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
- - 0
8
- - 9
9
7
  - 1
10
- version: 0.9.1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
+ - Michael Klett
14
+ - Jim Gay
15
+ - William Ross
16
+ - Tony Issakov
13
17
  - Dirk Kelly
14
18
  autorequire:
15
19
  bindir: bin
16
20
  cert_chain: []
17
21
 
18
- date: 2010-08-30 00:00:00 +08:00
22
+ date: 2010-10-20 00:00:00 +08:00
19
23
  default_executable:
20
24
  dependencies:
21
25
  - !ruby/object:Gem::Dependency
@@ -130,8 +134,8 @@ dependencies:
130
134
  version: 0.10.3
131
135
  type: :development
132
136
  version_requirements: *id007
133
- description: Provides extensions to standard layouts, including nesting of layouts within each other and sharing radiant layouts with rails controllers
134
- email: dk@squaretalent.com
137
+ description: Extends Radiant Layouts to support nesting, sharing with Rails Controllers and rendering HAML
138
+ email: dk@dirkkelly.com
135
139
  executables: []
136
140
 
137
141
  extensions: []
@@ -144,25 +148,31 @@ files:
144
148
  - README.md
145
149
  - Rakefile
146
150
  - VERSION
151
+ - app/models/haml_filter.rb
147
152
  - app/models/rails_page.rb
148
153
  - app/views/layouts/radiant.html.haml
154
+ - config/routes.rb
149
155
  - layouts_extension.rb
150
- - lib/nested_layouts.rb
151
- - lib/nested_layouts/tags.rb
152
- - lib/share_layouts.rb
153
- - lib/share_layouts/helper.rb
154
- - lib/share_layouts/radiant_layouts.rb
156
+ - lib/haml_layouts/models/layout.rb
157
+ - lib/haml_layouts/models/page.rb
158
+ - lib/nested_layouts/tags/core.rb
159
+ - lib/share_layouts/controllers/action_controller.rb
160
+ - lib/share_layouts/helpers/action_view.rb
155
161
  - lib/tasks/layouts_extension_tasks.rake
156
162
  - radiant-layouts-extension.gemspec
157
- - spec/controllers/nested_layouts_spec.rb
158
- - spec/controllers/share_layouts_spec.rb
159
- - spec/datasets/nested_layouts_dataset.rb
160
- - spec/datasets/share_layouts_dataset.rb
161
- - spec/helpers/share_layouts_helper_spec.rb
162
- - spec/lib/nested_layouts/tags_spec.rb
163
- - spec/lib/share_layouts_extension_spec.rb
163
+ - spec/controllers/share_controller_spec.rb
164
+ - spec/datasets/layouts_layouts.rb
165
+ - spec/datasets/layouts_pages.rb
166
+ - spec/lib/haml_layouts/haml_layouts_extension_spec.rb
167
+ - spec/lib/haml_layouts/models/layout_spec.rb
168
+ - spec/lib/haml_layouts/models/page_spec.rb
169
+ - spec/lib/nested_layouts/nested_layouts_extension_spec.rb
170
+ - spec/lib/nested_layouts/tags/core_spec.rb
171
+ - spec/lib/share_layouts/controllers/action_controller_spec.rb
172
+ - spec/lib/share_layouts/helpers/action_view_spec.rb
173
+ - spec/lib/share_layouts/share_layouts_extension_spec.rb
174
+ - spec/models/haml_filter_spec.rb
164
175
  - spec/models/rails_page_spec.rb
165
- - spec/rcov.opts
166
176
  - spec/spec.opts
167
177
  - spec/spec_helper.rb
168
178
  has_rdoc: true
@@ -198,14 +208,19 @@ rubyforge_project:
198
208
  rubygems_version: 1.3.7
199
209
  signing_key:
200
210
  specification_version: 3
201
- summary: Provides extensions to standard layouts, including nesting and sharing
211
+ summary: Extends Radiant Layouts to support nesting, sharing with Rails Controllers and rendering HAML
202
212
  test_files:
203
- - spec/controllers/nested_layouts_spec.rb
204
- - spec/controllers/share_layouts_spec.rb
205
- - spec/datasets/nested_layouts_dataset.rb
206
- - spec/datasets/share_layouts_dataset.rb
207
- - spec/helpers/share_layouts_helper_spec.rb
208
- - spec/lib/nested_layouts/tags_spec.rb
209
- - spec/lib/share_layouts_extension_spec.rb
213
+ - spec/controllers/share_controller_spec.rb
214
+ - spec/datasets/layouts_layouts.rb
215
+ - spec/datasets/layouts_pages.rb
216
+ - spec/lib/haml_layouts/haml_layouts_extension_spec.rb
217
+ - spec/lib/haml_layouts/models/layout_spec.rb
218
+ - spec/lib/haml_layouts/models/page_spec.rb
219
+ - spec/lib/nested_layouts/nested_layouts_extension_spec.rb
220
+ - spec/lib/nested_layouts/tags/core_spec.rb
221
+ - spec/lib/share_layouts/controllers/action_controller_spec.rb
222
+ - spec/lib/share_layouts/helpers/action_view_spec.rb
223
+ - spec/lib/share_layouts/share_layouts_extension_spec.rb
224
+ - spec/models/haml_filter_spec.rb
210
225
  - spec/models/rails_page_spec.rb
211
226
  - spec/spec_helper.rb
@@ -1,2 +0,0 @@
1
- module NestedLayouts
2
- end
@@ -1,127 +0,0 @@
1
- module NestedLayouts
2
- module Tags
3
- include Radiant::Taggable
4
-
5
- class TagError < StandardError; end
6
-
7
- desc %{
8
- Renders the contents of the tag inside of a "parent" layout, which is selected via the +name+
9
- attribute. The contents of this tag are placed at a corresponding <r:content_for_layout/> tag
10
- within the parent layout. This tag is intended to be used within your layouts, and should
11
- only appear once per layout.
12
-
13
- *Usage:*
14
-
15
- <r:inside_layout name="master">
16
- <div id="main-column">
17
- <r:content_for_layout/>
18
- </div>
19
- </r:inside_layout>
20
- }
21
- tag 'inside_layout' do |tag|
22
- if name = tag.attr['name']
23
- # Prepare the stacks
24
- tag.globals.nested_layouts_content_stack ||= []
25
- tag.globals.nested_layouts_layout_stack ||= []
26
-
27
- # Remember the original layout to support the +layout+ tag
28
- tag.globals.page_original_layout ||= tag.globals.page.layout # Remember the original layout
29
-
30
- # Find the layout
31
- name.strip!
32
- if layout = Layout.find_by_name(name)
33
- # Track this layout on the stack
34
- tag.globals.nested_layouts_layout_stack << name
35
-
36
- # Save contents of inside_layout for later insertion
37
- tag.globals.nested_layouts_content_stack << tag.expand
38
-
39
- # Set the page layout that Radiant should use for rendering, which is different than the actual
40
- # page's layout when layouts are nested. The final/highest +inside_layout+ tag will set or
41
- # overwrite this value for the last time.
42
- tag.globals.page.layout = layout
43
- tag.globals.page.render
44
- else
45
- raise TagError.new(%{Error (nested_layouts): Parent layout "#{name.strip}" not found for "inside_layout" tag})
46
- end
47
- else
48
- raise TagError.new(%{Error (nested_layouts): "inside_layout" tag must contain a "name" attribute})
49
- end
50
- end
51
-
52
- desc %{
53
- Allows nested layouts to target this layout. The contents of <r:inside_layout> tag blocks in another
54
- layout will have their contents inserted at the location given by this tag (if they target this
55
- layout). This tag also behaves like a standard <r:content/> tag if this layout is specified directly
56
- by a page.
57
-
58
- This tag is intended to be used inside layouts.
59
-
60
- *Usage:*
61
-
62
- <html>
63
- <body>
64
- <r:content_for_layout/>
65
- </body>
66
- </html>
67
-
68
- }
69
- tag 'content_for_layout' do |tag|
70
- tag.globals.nested_layouts_content_stack ||= []
71
-
72
- # return the saved content if any, or mimic a default +<r:content/>+ tag (render the body part)
73
- tag.globals.nested_layouts_content_stack.pop || tag.globals.page.render_snippet(tag.locals.page.part('body'))
74
- end
75
-
76
- desc %{
77
- Return the layout name of the current page.
78
-
79
- *Usage:*
80
-
81
- <html>
82
- <body id="<r:layout/>"
83
- My body tag has an id corresponding to the layout I use. Sweet!
84
- </body>
85
- </html>
86
- }
87
- tag 'layout' do |tag|
88
- if layout = tag.globals.page_original_layout
89
- layout.name
90
- else
91
- if layout = tag.globals.page.layout
92
- layout.name
93
- else
94
- ''
95
- end
96
- end
97
- end
98
-
99
- desc %{ output the contents of tag if layout equals name }
100
- tag 'if_layout' do |tag|
101
- if name = tag.attr['name']
102
- if layout = tag.globals.page_original_layout
103
- tag.expand if layout.name == name
104
- elsif layout = tag.globals.page.layout
105
- tag.expand if layout.name == name
106
- end
107
- else
108
- raise TagError.new(%{Error (nested_layouts): "if_layout" tag must contain a "name" attribute})
109
- end
110
- end
111
-
112
- desc %{ output the contents of tag unless layout equals name }
113
- tag 'unless_layout' do |tag|
114
- if name = tag.attr['name']
115
- if layout = tag.globals.page_original_layout
116
- tag.expand if layout.name != name
117
- elsif layout = tag.globals.page.layout
118
- tag.expand if layout.name != name
119
- else
120
- tag.expand
121
- end
122
- else
123
- raise TagError.new(%{Error (nested_layouts): "if_layout" tag must contain a "name" attribute})
124
- end
125
- end
126
- end
127
- end