tram-page 0.1.0 → 0.1.1

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: 890e2cc8021a94d4155ebc4a2647bb9049dda8cc
4
- data.tar.gz: f26c9d0e09a3e72ccf78bfc9014ac9e041c88bd6
3
+ metadata.gz: 375d5937b0f9c997aa2cd574e06c8f8899310e17
4
+ data.tar.gz: 629dd6b504f6ba91a71a52a4e33dd665ff1cfaee
5
5
  SHA512:
6
- metadata.gz: 62d4b2e9809b2df49e383d26d3d87b4f8df929786f0c92e60336225df29c389060d79289e3bfb63ca634147a3c30ad0110e3a13a73ad74b2d158dbc66fe2146e
7
- data.tar.gz: 30e9b419a6eaba364be62c8f51460b9d07bf87c2d593d311ded63dae3a6a56c921215bb20385d0ecb9839de16b947d4fb614b9fb66e41b42e69bd0dd51cc28ff
6
+ metadata.gz: a4b84cb6c46012e27c73d637abcce63a78c915210ffa93e923bec41314f546daaafaf84af668a4671c26c6be9676755ebf1de42ef722f0d4dc1e924e2f562b34
7
+ data.tar.gz: ec1fd25fba5e7e5aa0b74f94b0b20361c237b8e7a48c817857c655ac8e690f88a8d48678f9cd5525f68bbf6b262683fee5820a687e252b0e17a22c07eb1788ed
@@ -3,6 +3,6 @@
3
3
  # rubocop:disable Style/ClassAndModuleChildren
4
4
  module Tram
5
5
  class Page
6
- VERSION = "0.1.0"
6
+ VERSION = "0.1.1"
7
7
  end
8
8
  end
data/lib/tram/page.rb CHANGED
@@ -6,22 +6,34 @@ class Tram::Page
6
6
  class << self
7
7
  attr_accessor :i18n_scope
8
8
 
9
- def section(name, options = {}, &block)
9
+ def section(name, options = {})
10
10
  @__sections ||= []
11
- @__sections << [name, options, block]
11
+
12
+ n = name.dup.to_sym
13
+ if @__sections.map(&:first).include?(n)
14
+ raise "Section #{n} already exists"
15
+ end
16
+ n = define_section_method(n, options)
17
+ @__sections << [n, options]
12
18
  end
13
19
 
14
20
  def url_helper(name)
15
21
  raise "Rails url_helpers module is not defined" unless defined?(Rails)
16
22
  delegate name, to: :"Rails.application.routes.url_helpers"
17
23
  end
24
+
25
+ private
26
+
27
+ def define_section_method(n, options)
28
+ return n unless options[:value]
29
+ define_method(n) { instance_exec(&options[:value]) }
30
+ n
31
+ end
18
32
  end
19
33
 
20
34
  def to_h(options = {})
21
- data = page_methods(options).map do |(name, opts, block)|
22
- value = instance_eval(&block) if block
23
- value ||= public_send(opts[:method] || name)
24
-
35
+ data = page_methods(options).map do |(name, opts)|
36
+ value = public_send(opts[:method] || name)
25
37
  [name, value]
26
38
  end
27
39
  Hash[data]
@@ -38,7 +50,7 @@ class Tram::Page
38
50
  methods = self.class.instance_variable_get(:"@__sections") || []
39
51
  except = Array(options[:except])
40
52
  only = Array(options[:only])
41
- methods.reject do |(name, _, _)|
53
+ methods.reject do |(name, _)|
42
54
  (except.any? && except.include?(name)) ||
43
55
  (only.any? && !only.include?(name))
44
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tram-page
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Sokolov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler