curly-templates 2.4.1 → 2.5.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: 2f038cf925ee66f41bb273477733836d3be22594
4
- data.tar.gz: 8d39cf352d8638c847154ce3fdccbcbfca9ae4a7
3
+ metadata.gz: 771f76ff2fc6fc4e3947ee8a205897a9930a02cc
4
+ data.tar.gz: 98c36121c84ad15081e32868ca1c8613365ea6ed
5
5
  SHA512:
6
- metadata.gz: 8616749a1fe10664053e2048059a19618ad2b5d6878fce96587b39cc7322565349099ece2e40737f55404ee84de4e041227270f0be18e02de0fd2a2627d42979
7
- data.tar.gz: 59036f8b9086a6196ba1c99291e6701f2f99735cc45dbc23b80c00123662618b71ae7f233cd814a66a8ef93a15bdd70341ee2cafb463b46be8f9a39e4cec120c
6
+ metadata.gz: 9893fb5b0c90b082c462128dd4bbd889d375f2913c703ae52b9d97cdb6dcf2de54f92e08032d8efd1007815a50672820bc5902a71fc5001723213719575bac29
7
+ data.tar.gz: 6ba0441db8486cdf248debd4e9d7f95d5ef8eafb2cbb53153684b5367679ada012206b289285a8c65eb94455c3a33b91209457814cf46829faf76f77f179bfc3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ### Unreleased
2
2
 
3
+ ### Curly 2.5.0 (May 19, 2015)
4
+
5
+ * Allow passing a block as the `default:` option to `presents`.
6
+
7
+ ```ruby
8
+ class CommentPresenter < Curly::Presenter
9
+ presents :comment
10
+ presents(:author) { @comment.author }
11
+ end
12
+ ```
13
+
14
+ *Steven Davidovitz & Jeremy Rodi*
15
+
3
16
  ### Curly 2.4.0 (February 24, 2015)
4
17
 
5
18
  * Add an `exposes_helper` class methods to Curly::Presenter. This allows exposing
data/README.md CHANGED
@@ -702,6 +702,7 @@ Thanks to [Zendesk](http://zendesk.com/) for sponsoring the work on Curly.
702
702
  - Alisson Cavalcante Agiani ([@thelinuxlich](https://github.com/thelinuxlich))
703
703
  - Łukasz Niemier ([@hauleth](https://github.com/hauleth))
704
704
  - Cristian Planas ([@Gawyn](https://github.com/Gawyn))
705
+ - Steven Davidovitz ([@steved](https://github.com/steved))
705
706
 
706
707
 
707
708
  Build Status
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'curly-templates'
7
- s.version = '2.4.1'
8
- s.date = '2015-04-27'
7
+ s.version = '2.5.0'
8
+ s.date = '2015-05-19'
9
9
 
10
10
  s.summary = "Free your views!"
11
11
  s.description = "A view layer for your Rails apps that separates structure and logic."
data/lib/curly.rb CHANGED
@@ -25,7 +25,7 @@
25
25
  #
26
26
  # See Curly::Presenter for more information on presenters.
27
27
  module Curly
28
- VERSION = "2.4.1"
28
+ VERSION = "2.5.0"
29
29
 
30
30
  # Compiles a Curly template to Ruby code.
31
31
  #
@@ -48,7 +48,11 @@ module Curly
48
48
  self.class.presented_names.each do |name|
49
49
  value = options.fetch(name) do
50
50
  default_values.fetch(name) do
51
- raise ArgumentError.new("required identifier `#{name}` missing")
51
+ block = default_blocks.fetch(name) do
52
+ raise ArgumentError.new("required identifier `#{name}` missing")
53
+ end
54
+
55
+ instance_exec(name, &block)
52
56
  end
53
57
  end
54
58
 
@@ -281,17 +285,23 @@ module Curly
281
285
  [name, version, dependency_cache_keys].flatten.join("/")
282
286
  end
283
287
 
284
- def presents(*args)
285
- options = args.extract_options!
288
+ def presents(*args, **options, &block)
289
+ if options.key?(:default) && block_given?
290
+ raise ArgumentError, "Cannot provide both `default:` and block"
291
+ end
286
292
 
287
293
  self.presented_names += args.map(&:to_s)
288
294
 
289
295
  if options.key?(:default)
290
- default_values = args.each_with_object(Hash.new) do |arg, hash|
291
- hash[arg.to_s] = options.fetch(:default)
296
+ args.each do |arg|
297
+ self.default_values = default_values.merge(arg.to_s => options[:default]).freeze
292
298
  end
299
+ end
293
300
 
294
- self.default_values = self.default_values.merge(default_values)
301
+ if block_given?
302
+ args.each do |arg|
303
+ self.default_blocks = default_blocks.merge(arg.to_s => block).freeze
304
+ end
295
305
  end
296
306
  end
297
307
 
@@ -308,10 +318,11 @@ module Curly
308
318
 
309
319
  private
310
320
 
311
- class_attribute :presented_names, :default_values
321
+ class_attribute :presented_names, :default_values, :default_blocks
312
322
 
313
323
  self.presented_names = [].freeze
314
324
  self.default_values = {}.freeze
325
+ self.default_blocks = {}.freeze
315
326
 
316
327
  delegate :render, to: :@_context
317
328
 
@@ -11,8 +11,11 @@ describe Curly::Presenter do
11
11
 
12
12
  presents :midget, :clown, default: nil
13
13
  presents :elephant, default: "Dumbo"
14
+ presents :puma, default: -> { 'block' }
15
+ presents(:lion) { @elephant.upcase }
16
+ presents(:something) { self }
14
17
 
15
- attr_reader :midget, :clown, :elephant
18
+ attr_reader :midget, :clown, :elephant, :puma, :lion, :something
16
19
  end
17
20
 
18
21
  class FrenchCircusPresenter < CircusPresenter
@@ -49,10 +52,25 @@ describe Curly::Presenter do
49
52
  # Make sure subclasses can change default values.
50
53
  french_presenter = FrenchCircusPresenter.new(context)
51
54
  french_presenter.elephant.should == "Babar"
55
+ french_presenter.lion.should == 'BABAR'
56
+ french_presenter.puma.should be_a Proc
52
57
 
53
58
  # The subclass shouldn't change the superclass' defaults, though.
54
59
  presenter = CircusPresenter.new(context)
55
60
  presenter.elephant.should == "Dumbo"
61
+ presenter.lion.should == 'DUMBO'
62
+ presenter.puma.should be_a Proc
63
+ end
64
+
65
+ it "doesn't call a block if given as a value for identifiers" do
66
+ lion = proc { 'Simba' }
67
+ presenter = CircusPresenter.new(context, lion: lion)
68
+ presenter.lion.should be lion
69
+ end
70
+
71
+ it "calls default blocks in the instance of the presenter" do
72
+ presenter = CircusPresenter.new(context)
73
+ presenter.something.should be presenter
56
74
  end
57
75
  end
58
76
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curly-templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack