mountain_view 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67887fb2ae93d0eac1d9885cf29dcdf662415a96
4
- data.tar.gz: 6940be95e5c1c73fd4122494ab7dafb375505a80
3
+ metadata.gz: 1492e39aab18154eb640fe41234f348137c41523
4
+ data.tar.gz: b02850181a73d4770cdc21b06d2d316acc185792
5
5
  SHA512:
6
- metadata.gz: c644d342583ac28525909af5d5d0cc4d437e037853017e483cdf226091d151e2f7464fdbc9afb854cf898140a1c3fc322f423daa3628e74e5a48d3ab40587861
7
- data.tar.gz: 3578fc09a249f2e05afcdf37193868bb49623735d7c0595c0050b9f1501a9e34e5e2708bde9d58ace2f7e5185ddef95b26e37e91729ad9b8e5d4619a65b189ca
6
+ metadata.gz: e9c2bb5124b7e27314d536d6bed2ee02fb4658928600aa9fe365157594cca662dd7bfb30dbed34c16710e1f19cb45c098acfe8117dbce8e23636bad8f34fdbb1
7
+ data.tar.gz: e91297418a2bef52a765f2ce598e837af274a1856c260202d57d68f98bd9a81395f821ecd0b9ad7ece1b47874810f86c818b892d0ce53dade5cb8cf9ab39f1c1
data/README.md CHANGED
@@ -107,6 +107,33 @@ helper:
107
107
  <%= render_component "header", title: "This is a title", subtitle: "And this is a subtitle" %>
108
108
  ```
109
109
 
110
+ ### Yielding content
111
+
112
+ You can also pass a block to a component, for example the following component:
113
+
114
+ ```erb
115
+ <!-- app/components/header/_header.html.erb -->
116
+ <div class="header">
117
+ <%= properties[:yield] %>
118
+ </div>
119
+ ```
120
+
121
+ Used in a view like so:
122
+ ```erb
123
+ <%= render_component "header" do %>
124
+ <p>Hello World</p>
125
+ <% end %>
126
+ ```
127
+
128
+ Would output the following in your view:
129
+
130
+ ```erb
131
+ <div class="header">
132
+ <p>Hello World</p>
133
+ </div>
134
+ ```
135
+
136
+
110
137
  ### Assets
111
138
  You can require all the components CSS and JS automatically by requiring `mountain_view` in your main JS and CSS files.
112
139
 
data/Rakefile CHANGED
@@ -26,6 +26,7 @@ Rake::TestTask.new(:test) do |t|
26
26
  t.libs << 'test'
27
27
  t.pattern = 'test/**/*_test.rb'
28
28
  t.verbose = false
29
+ t.warning = false
29
30
  end
30
31
 
31
32
 
@@ -1,8 +1,10 @@
1
1
  module MountainView
2
2
  module ComponentHelper
3
- def render_component(slug, properties = {})
3
+ def render_component(slug, properties = {}, &block)
4
4
  component = MountainView::Presenter.component_for(slug, properties)
5
- component.render(controller.view_context)
5
+ component.render(controller.view_context) do
6
+ capture(&block) if block_given?
7
+ end
6
8
  end
7
9
  end
8
10
  end
@@ -10,10 +10,11 @@ module MountainView
10
10
  @properties = default_properties.deep_merge(properties)
11
11
  end
12
12
 
13
- def render(context)
13
+ def render(context, &block)
14
14
  context.extend ViewContext
15
15
  context.inject_component_context self
16
- context.render partial: partial
16
+ properties[:yield] ||= yield
17
+ context.render partial, partial: partial
17
18
  end
18
19
 
19
20
  def partial
@@ -1,3 +1,3 @@
1
1
  module MountainView
2
- VERSION = "0.10.0".freeze
2
+ VERSION = "0.11.0".freeze
3
3
  end
@@ -0,0 +1,6 @@
1
+ <div class="yielder">
2
+ <p>Tell me about the Proc?</p>
3
+ <div class="yield-here">
4
+ <%= properties[:yield] %>
5
+ </div>
6
+ </div>
File without changes
File without changes
File without changes
@@ -39,7 +39,7 @@ module Dummy
39
39
  config.eager_load = false
40
40
 
41
41
  # Configure static asset server for tests with Cache-Control for performance.
42
- config.static_cache_control = 'public, max-age=3600'
42
+ # config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
43
43
 
44
44
  config.assets.enabled = true
45
45
 
@@ -9,4 +9,39 @@ class MountainView::ComponentHelperTest < ActionView::TestCase
9
9
  assert_match expected, rendered
10
10
  assert_match %r(href=\"\/products\/1\"), rendered
11
11
  end
12
+
13
+ test "renders when passed a block" do
14
+ rendered = render_component("yielder") do
15
+ "I appear to be in a block"
16
+ end
17
+
18
+ expected = /<div class=\"yield-here\">\n I appear to be in a block\n <\/div>/
19
+ assert_match expected, rendered
20
+ assert_match /Tell me about the Proc/, rendered
21
+ end
22
+
23
+ test "Does not override passed yield property with block" do
24
+ rendered = render_component("yielder", yield: "It is me in the block") do
25
+ "I appear to be in a block"
26
+ end
27
+
28
+ expected = /<div class=\"yield-here\">\n It is me in the block\n <\/div>/
29
+ assert_match expected, rendered
30
+ assert_match /Tell me about the Proc/, rendered
31
+ end
32
+
33
+ test "renders when has a yield, but no block passed" do
34
+ rendered = render_component("yielder")
35
+
36
+ assert_match /Tell me about the Proc/, rendered
37
+ end
38
+
39
+ test "renders a component within a compontent" do
40
+ rendered = render_component("yielder") do
41
+ render_component("header", id: 1, title: "Pepe")
42
+ end
43
+
44
+ assert_match /Pepe/, rendered
45
+ assert_match %r(href=\"\/products\/1\"), rendered
46
+ end
12
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mountain_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Gutierrez
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-02 00:00:00.000000000 Z
12
+ date: 2017-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -93,6 +93,10 @@ files:
93
93
  - test/dummy/app/components/header/header.js
94
94
  - test/dummy/app/components/header/header.yml
95
95
  - test/dummy/app/components/paragraph/_paragraph.html.erb
96
+ - test/dummy/app/components/yielder/_yielder.html.erb
97
+ - test/dummy/app/components/yielder/yielder.css
98
+ - test/dummy/app/components/yielder/yielder.js
99
+ - test/dummy/app/components/yielder/yielder.yml
96
100
  - test/dummy/app/controllers/application_controller.rb
97
101
  - test/dummy/app/controllers/home_controller.rb
98
102
  - test/dummy/app/helpers/application_helper.rb
@@ -181,6 +185,10 @@ test_files:
181
185
  - test/dummy/app/components/header/header.js
182
186
  - test/dummy/app/components/header/header.yml
183
187
  - test/dummy/app/components/paragraph/_paragraph.html.erb
188
+ - test/dummy/app/components/yielder/_yielder.html.erb
189
+ - test/dummy/app/components/yielder/yielder.css
190
+ - test/dummy/app/components/yielder/yielder.js
191
+ - test/dummy/app/components/yielder/yielder.yml
184
192
  - test/dummy/app/controllers/application_controller.rb
185
193
  - test/dummy/app/controllers/home_controller.rb
186
194
  - test/dummy/app/helpers/application_helper.rb