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 +4 -4
- data/lib/tram/page/version.rb +1 -1
- data/lib/tram/page.rb +19 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 375d5937b0f9c997aa2cd574e06c8f8899310e17
|
4
|
+
data.tar.gz: 629dd6b504f6ba91a71a52a4e33dd665ff1cfaee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4b84cb6c46012e27c73d637abcce63a78c915210ffa93e923bec41314f546daaafaf84af668a4671c26c6be9676755ebf1de42ef722f0d4dc1e924e2f562b34
|
7
|
+
data.tar.gz: ec1fd25fba5e7e5aa0b74f94b0b20361c237b8e7a48c817857c655ac8e690f88a8d48678f9cd5525f68bbf6b262683fee5820a687e252b0e17a22c07eb1788ed
|
data/lib/tram/page/version.rb
CHANGED
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 = {}
|
9
|
+
def section(name, options = {})
|
10
10
|
@__sections ||= []
|
11
|
-
|
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
|
22
|
-
value =
|
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.
|
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-
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|