nestive 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjQyMmRkZWQ4OTUzODczYmQ3ZmRjYWI5MDZkODYzNDY5MGViNTcyMg==
5
+ data.tar.gz: !binary |-
6
+ MTcxOWVjYjA0M2M3NjZmZDUyYWY4NWRiOTc5MjRlMjVlNDZlZDljNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZWFlMzM1ODY2MGE1YjQzZTM3ZjdhYTRmMzhlMTFiZWQ0OTkxNGZlOTQwNGM3
10
+ NGRlNzUzYTI4NGEzZjUzNDRhNjUwMjlkZjM0OTU1ZTJiYzYyNWQxZjI5YzJk
11
+ NjM1MjI4MzRlNjk5MWU0Mzc2NmUyOWM3MTUyMjU0YzhiYWE0M2Y=
12
+ data.tar.gz: !binary |-
13
+ ZDA3NGRlZGZjODc5ZGNjODMwYTIwZGU1NjMyMTY5YzMwY2ZhYzE5YzYxYjJj
14
+ YWIyYzdhYjE1ODY3MzY4NGNjYTIzMjM2ZDBlZGMwMGIwYzNkMzRhYzVkZDk3
15
+ NDA0OTgyNzUzNTllMDJlNzA2OTFkY2I2NzBiMmZlZjZlMDUwMTE=
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .rvmrc
2
2
  doc
3
3
  .yardoc
4
- pkg
4
+ pkg
5
+ Gemfile.lock
@@ -1,4 +1,5 @@
1
1
  rvm:
2
+ - 2.0.0
2
3
  - 1.9.3
3
4
  - 1.9.2
4
5
  - 1.8.7
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify dependencies in nestive.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'combustion', '~> 0.4.0'
8
+ gem 'rspec-rails', '~> 2.13'
9
+ end
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
- # Nestive
2
- [![Build Status](https://travis-ci.org/rwz/nestive.png)](https://travis-ci.org/rwz/nestive)
3
- ## A Nested Inheritable Layouts Plugin for Rails
1
+ # Nestive [![Build Status](https://travis-ci.org/rwz/nestive.png)](https://travis-ci.org/rwz/nestive) [![Code Climate](https://codeclimate.com/github/rwz/nestive.png)](https://codeclimate.com/github/rwz/nestive)
2
+ ## A Nested Inheritable Layouts Helpers for Rails
4
3
 
5
4
 
6
5
  Nestive adds powerful layout and view helpers to your Rails app. It's similar to the nested layout technique [already documented in the Rails guides](http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts) and found in many other nested layout plugins (a technique using `content_for` and rendering the parent layout at the end of the child layout). There's a bunch of problems with this technique, including:
@@ -10,9 +9,9 @@ Nestive adds powerful layout and view helpers to your Rails app. It's similar to
10
9
 
11
10
  Nestive is *better* because it addresses these problems.
12
11
 
13
- ## Just five methods (so far) – `area`, `extends`, `append`, `prepend`, `replace`.
12
+ ## Just six methods (so far)
14
13
 
15
- ### Declaring an area of content in your parent layout with `area`:
14
+ ### Declaring an area of content with `area`:
16
15
 
17
16
  The `area` helper is a lot like Rails' own `<%= yield :foo %>`, and is used in layouts to define and render a chunk of content in your layout:
18
17
 
@@ -32,7 +31,7 @@ Unlike `yield`, `area` will allow your parent layouts to add content to the area
32
31
 
33
32
  It's important to note that this isn't *default* content, it *is* the content (unless a child changes it).
34
33
 
35
- ### Appending content to an area:
34
+ ### Appending content to an area with `append`:
36
35
 
37
36
  The implementation details are quite different, but the `append` helper works much like Rails' built-in `content_for`. It will work with either a String or block, adding the new content onto the end of any content previously provided by parent layouts:
38
37
 
@@ -45,7 +44,7 @@ The implementation details are quite different, but the `append` helper works mu
45
44
  <% end %>
46
45
  ```
47
46
 
48
- ### Prepending content to an area:
47
+ ### Prepending content to an area with `prepend`:
49
48
 
50
49
  Exactly what you think it is. The reverse of `append` (duh), adding the new content at the start of any content previously provided by parent layouts:
51
50
 
@@ -58,7 +57,7 @@ Exactly what you think it is. The reverse of `append` (duh), adding the new cont
58
57
  <% end %>
59
58
  ```
60
59
 
61
- ### Replacing content
60
+ ### Replacing content with `replace`
62
61
 
63
62
  You can also replace any content provided by parent layouts:
64
63
 
@@ -71,7 +70,21 @@ You can also replace any content provided by parent layouts:
71
70
  <% end %>
72
71
  ```
73
72
 
74
- ### Extending a layout in a child layout (or view):
73
+ ### Removing content with `purge`
74
+
75
+ You can remove the content of the area:
76
+
77
+ ``` erb
78
+ <% purge :sidebar %>
79
+ ```
80
+
81
+ ... which is equal to:
82
+
83
+ ``` erb
84
+ <% replace :sidebar, nil %>
85
+ ```
86
+
87
+ ### Extending a layout in a child layout (or view) with `extends`
75
88
 
76
89
  Any layout (or view) can declare that it wants to inherit from and extend a parent layout, in this case we're extending `app/views/layouts/application.html.erb`:
77
90
 
@@ -204,7 +217,7 @@ end
204
217
 
205
218
  ## Installation
206
219
 
207
- * add `gem 'nestive', '~> 0.2'` to your Gemfile
220
+ * add `gem 'nestive', '~> 0.4'` to your Gemfile
208
221
  * run `bundle`
209
222
 
210
223
  ## Compatibility
@@ -54,8 +54,8 @@ module Nestive
54
54
 
55
55
  # Declares that the current layour (or view) is inheriting from and extending another layout.
56
56
  #
57
- # @param [Symbol] name
58
- # The base name of the file in `layouts/` that you wish to extend (eg `:application` for `layouts/application.html.erb`)
57
+ # @param [String] layout
58
+ # The base name of the file in `layouts/` that you wish to extend (eg `application` for `layouts/application.html.erb`)
59
59
  #
60
60
  # @example Extending the `application` layout to create an `admin` layout
61
61
  #
@@ -86,7 +86,7 @@ module Nestive
86
86
  layout = layout.to_s
87
87
 
88
88
  # If there's no directory component, presume a plain layout name
89
- layout = layout.include?('/') ? layout : "layouts/#{layout}"
89
+ layout = "layouts/#{layout}" unless layout.include?('/')
90
90
 
91
91
  # Capture the content to be placed inside the extended layout
92
92
  content_for(:layout).replace capture(&block)
@@ -126,13 +126,8 @@ module Nestive
126
126
  # An optional String of content to add to the area as you declare it.
127
127
  def area(name, content=nil, &block)
128
128
  content = capture(&block) if block_given?
129
- append(name, content)
130
- render_area(name)
131
- end
132
-
133
- def block(name, content=nil, &block)
134
- ActiveSupport::Deprecation.warn("block() is deprecated and will be removed very soon, please use area() instead")
135
- area(name, content, &block)
129
+ append name, content
130
+ render_area name
136
131
  end
137
132
 
138
133
  # Appends content to an area previously defined or modified in parent layout(s). You can provide
@@ -153,8 +148,7 @@ module Nestive
153
148
  # Optionally provide a String of content, instead of a block. A block will take precedence.
154
149
  def append(name, content=nil, &block)
155
150
  content = capture(&block) if block_given?
156
- add_instruction_to_area(name, :push, content)
157
- nil
151
+ add_instruction_to_area name, :push, content
158
152
  end
159
153
 
160
154
  # Prepends content to an area previously declared or modified in parent layout(s). You can
@@ -175,17 +169,16 @@ module Nestive
175
169
  # Optionally provide a String of content, instead of a block. A block will take precedence.
176
170
  def prepend(name, content=nil, &block)
177
171
  content = capture(&block) if block_given?
178
- add_instruction_to_area(name, :unshift, content)
179
- nil
172
+ add_instruction_to_area name, :unshift, content
180
173
  end
181
174
 
182
175
  # Replaces the content of an area previously declared or modified in parent layout(s). You can
183
176
  # provide the content using either a String, or a block.
184
177
  #
185
- # @example Prepending content with a String
178
+ # @example Replacing content with a String
186
179
  # <% replace :sidebar, "New content." %>
187
180
  #
188
- # @example Prepending content with a block:
181
+ # @example Replacing content with a block:
189
182
  # <% replace :sidebar do %>
190
183
  # New content.
191
184
  # <% end %>
@@ -197,8 +190,18 @@ module Nestive
197
190
  # Optionally provide a String of content, instead of a block. A block will take precedence.
198
191
  def replace(name, content=nil, &block)
199
192
  content = capture(&block) if block_given?
200
- add_instruction_to_area(name, :replace, [content])
201
- nil
193
+ add_instruction_to_area name, :replace, [content]
194
+ end
195
+
196
+ # Purge the content of an area previously declared or modified in parent layout(s).
197
+ #
198
+ # @example Purge content
199
+ # <% purge :sidebar %>
200
+ #
201
+ # @param [Symbol] name
202
+ # A name to identify the area of content you wish to purge
203
+ def purge(name)
204
+ replace name, nil
202
205
  end
203
206
 
204
207
  private
@@ -221,6 +224,7 @@ module Nestive
221
224
  @_area_for ||= {}
222
225
  @_area_for[name] ||= []
223
226
  @_area_for[name] << [instruction, value]
227
+ nil
224
228
  end
225
229
 
226
230
  # Take the instructions we've gathered for the area and replay them one after the other on
@@ -232,11 +236,11 @@ module Nestive
232
236
  #
233
237
  # @todo is `html_safe` "safe" here?
234
238
  def render_area(name)
235
- output = []
236
- (@_area_for[name] || []).reverse.each do |i|
237
- output.send(i.first, i.last)
238
- end
239
- output.join.html_safe
239
+ [].tap do |output|
240
+ @_area_for.fetch(name, []).reverse_each do |i|
241
+ output.send i.first, i.last
242
+ end
243
+ end.join.html_safe
240
244
  end
241
245
 
242
246
  end
@@ -1,3 +1,3 @@
1
1
  module Nestive
2
- VERSION = '0.2.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -3,16 +3,16 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
  require 'nestive/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "nestive"
7
- s.version = Nestive::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ['Justin French', 'Pavel Pravosud']
10
- s.email = ['justin@indent.com.au', 'pavel@pravosud.com']
11
- s.homepage = 'https://github.com/rwz/nestive'
12
- s.summary = 'A Rails plugin/gem for awesome nested templates and layouts'
13
- s.description = 'A Rails plugin/gem for awesome nested templates and layouts'
6
+ s.name = 'nestive'
7
+ s.version = Nestive::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Justin French', 'Pavel Pravosud']
10
+ s.email = ['justin@indent.com.au', 'pavel@pravosud.com']
11
+ s.homepage = 'https://github.com/rwz/nestive'
12
+ s.summary = 'A Rails gem for awesome nested templates and layouts'
13
+ s.description = 'A Rails plugin/gem for awesome nested templates and layouts'
14
+ s.licenses = ['MIT']
14
15
 
15
- s.rubyforge_project = 'nestive'
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -20,7 +20,4 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ['lib']
21
21
 
22
22
  s.add_dependency 'rails', '>= 3.0.0'
23
- s.add_development_dependency 'combustion', '~> 0.3.3'
24
- s.add_development_dependency 'rspec-rails', '~> 2.12'
25
-
26
23
  end
@@ -55,7 +55,14 @@ describe NestiveController do
55
55
  assert_select '#some-area', 'replaced'
56
56
  end
57
57
  end
58
-
58
+
59
+ context '#purge' do
60
+ it 'purge area content' do
61
+ get :purge
62
+ assert_select 'title'
63
+ end
64
+ end
65
+
59
66
  context '#extends' do
60
67
  it 'extends layouts' do
61
68
  get :extended_one
@@ -0,0 +1,3 @@
1
+ <h1>purge area</h1>
2
+
3
+ <% purge :title %>
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nestive
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.1
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Justin French
@@ -10,56 +9,22 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-02-02 00:00:00.000000000 Z
12
+ date: 2013-04-14 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  prerelease: false
16
+ name: rails
17
17
  version_requirements: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 3.0.0
22
- none: false
23
- type: :runtime
24
- name: rails
25
22
  requirement: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
- none: false
31
- - !ruby/object:Gem::Dependency
32
- prerelease: false
33
- version_requirements: !ruby/object:Gem::Requirement
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 0.3.3
38
- none: false
39
- type: :development
40
- name: combustion
41
- requirement: !ruby/object:Gem::Requirement
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 0.3.3
46
- none: false
47
- - !ruby/object:Gem::Dependency
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '2.12'
54
- none: false
55
- type: :development
56
- name: rspec-rails
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '2.12'
62
- none: false
27
+ type: :runtime
63
28
  description: A Rails plugin/gem for awesome nested templates and layouts
64
29
  email:
65
30
  - justin@indent.com.au
@@ -72,14 +37,11 @@ files:
72
37
  - .travis.yml
73
38
  - .yardopts
74
39
  - Gemfile
75
- - Gemfile.lock
76
40
  - MIT-LICENSE
77
41
  - README.md
78
42
  - Rakefile
79
43
  - app/helpers/nestive/layout_helper.rb
80
44
  - config.ru
81
- - init.rb
82
- - install.rb
83
45
  - lib/nestive.rb
84
46
  - lib/nestive/engine.rb
85
47
  - lib/nestive/railtie.rb
@@ -96,15 +58,17 @@ files:
96
58
  - spec/internal/app/views/nestive/extended_two.html.erb
97
59
  - spec/internal/app/views/nestive/index.html.erb
98
60
  - spec/internal/app/views/nestive/prepend.html.erb
61
+ - spec/internal/app/views/nestive/purge.html.erb
99
62
  - spec/internal/app/views/nestive/replace.html.erb
100
63
  - spec/internal/config/routes.rb
101
64
  - spec/internal/db/schema.rb
102
65
  - spec/internal/log/.gitignore
103
66
  - spec/internal/public/favicon.ico
104
67
  - spec/spec_helper.rb
105
- - uninstall.rb
106
68
  homepage: https://github.com/rwz/nestive
107
- licenses: []
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
108
72
  post_install_message:
109
73
  rdoc_options: []
110
74
  require_paths:
@@ -114,19 +78,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
78
  - - ! '>='
115
79
  - !ruby/object:Gem::Version
116
80
  version: '0'
117
- none: false
118
81
  required_rubygems_version: !ruby/object:Gem::Requirement
119
82
  requirements:
120
83
  - - ! '>='
121
84
  - !ruby/object:Gem::Version
122
85
  version: '0'
123
- none: false
124
86
  requirements: []
125
- rubyforge_project: nestive
126
- rubygems_version: 1.8.25
87
+ rubyforge_project:
88
+ rubygems_version: 2.0.3
127
89
  signing_key:
128
- specification_version: 3
129
- summary: A Rails plugin/gem for awesome nested templates and layouts
90
+ specification_version: 4
91
+ summary: A Rails gem for awesome nested templates and layouts
130
92
  test_files:
131
93
  - spec/controllers/nestive_spec.rb
132
94
  - spec/internal/app/controllers/application_controller.rb
@@ -139,6 +101,7 @@ test_files:
139
101
  - spec/internal/app/views/nestive/extended_two.html.erb
140
102
  - spec/internal/app/views/nestive/index.html.erb
141
103
  - spec/internal/app/views/nestive/prepend.html.erb
104
+ - spec/internal/app/views/nestive/purge.html.erb
142
105
  - spec/internal/app/views/nestive/replace.html.erb
143
106
  - spec/internal/config/routes.rb
144
107
  - spec/internal/db/schema.rb
@@ -1,109 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- nestive (0.2.0)
5
- rails (>= 3.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actionmailer (3.2.11)
11
- actionpack (= 3.2.11)
12
- mail (~> 2.4.4)
13
- actionpack (3.2.11)
14
- activemodel (= 3.2.11)
15
- activesupport (= 3.2.11)
16
- builder (~> 3.0.0)
17
- erubis (~> 2.7.0)
18
- journey (~> 1.0.4)
19
- rack (~> 1.4.0)
20
- rack-cache (~> 1.2)
21
- rack-test (~> 0.6.1)
22
- sprockets (~> 2.2.1)
23
- activemodel (3.2.11)
24
- activesupport (= 3.2.11)
25
- builder (~> 3.0.0)
26
- activerecord (3.2.11)
27
- activemodel (= 3.2.11)
28
- activesupport (= 3.2.11)
29
- arel (~> 3.0.2)
30
- tzinfo (~> 0.3.29)
31
- activeresource (3.2.11)
32
- activemodel (= 3.2.11)
33
- activesupport (= 3.2.11)
34
- activesupport (3.2.11)
35
- i18n (~> 0.6)
36
- multi_json (~> 1.0)
37
- arel (3.0.2)
38
- builder (3.0.4)
39
- combustion (0.3.3)
40
- rails (>= 3.0.0)
41
- thor (>= 0.14.6)
42
- diff-lcs (1.1.3)
43
- erubis (2.7.0)
44
- hike (1.2.1)
45
- i18n (0.6.1)
46
- journey (1.0.4)
47
- json (1.7.6)
48
- mail (2.4.4)
49
- i18n (>= 0.4.0)
50
- mime-types (~> 1.16)
51
- treetop (~> 1.4.8)
52
- mime-types (1.19)
53
- multi_json (1.5.0)
54
- polyglot (0.3.3)
55
- rack (1.4.4)
56
- rack-cache (1.2)
57
- rack (>= 0.4)
58
- rack-ssl (1.3.3)
59
- rack
60
- rack-test (0.6.2)
61
- rack (>= 1.0)
62
- rails (3.2.11)
63
- actionmailer (= 3.2.11)
64
- actionpack (= 3.2.11)
65
- activerecord (= 3.2.11)
66
- activeresource (= 3.2.11)
67
- activesupport (= 3.2.11)
68
- bundler (~> 1.0)
69
- railties (= 3.2.11)
70
- railties (3.2.11)
71
- actionpack (= 3.2.11)
72
- activesupport (= 3.2.11)
73
- rack-ssl (~> 1.3.2)
74
- rake (>= 0.8.7)
75
- rdoc (~> 3.4)
76
- thor (>= 0.14.6, < 2.0)
77
- rake (10.0.3)
78
- rdoc (3.12)
79
- json (~> 1.4)
80
- rspec-core (2.12.2)
81
- rspec-expectations (2.12.1)
82
- diff-lcs (~> 1.1.3)
83
- rspec-mocks (2.12.2)
84
- rspec-rails (2.12.2)
85
- actionpack (>= 3.0)
86
- activesupport (>= 3.0)
87
- railties (>= 3.0)
88
- rspec-core (~> 2.12.0)
89
- rspec-expectations (~> 2.12.0)
90
- rspec-mocks (~> 2.12.0)
91
- sprockets (2.2.2)
92
- hike (~> 1.2)
93
- multi_json (~> 1.0)
94
- rack (~> 1.0)
95
- tilt (~> 1.1, != 1.3.0)
96
- thor (0.17.0)
97
- tilt (1.3.3)
98
- treetop (1.4.12)
99
- polyglot
100
- polyglot (>= 0.3.1)
101
- tzinfo (0.3.35)
102
-
103
- PLATFORMS
104
- ruby
105
-
106
- DEPENDENCIES
107
- combustion (~> 0.3.3)
108
- nestive!
109
- rspec-rails (~> 2.12)
data/init.rb DELETED
@@ -1 +0,0 @@
1
- # Include hook code here
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # Install hook code here
@@ -1 +0,0 @@
1
- # Uninstall hook code here