resulang 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9f8ee4aa6b963ea749c10954d042c71f2099c9b7ad9267921ce99099223ba0c
4
- data.tar.gz: 54cd1b85136bd67d37de5ad8c7b9ab222ca3341bd937e1d5e543ab0b8113a73d
3
+ metadata.gz: f77e7c4836d3b5579f4ab1389d961a70425894353419b91d4b41927a37581c25
4
+ data.tar.gz: fdeb85325dc87404c955436154b388445e823ac44c10b044eb53833b513dbb2f
5
5
  SHA512:
6
- metadata.gz: fa6c3890faa19934257f5547c40564c5a44c0efb22c8cb49034d499be7ca8893aa36efbd69009685cf418423b71411bb1bd272a823aa43781f53e89d4a475ec5
7
- data.tar.gz: b16d1895f0b89839d5bda160952006c77e9b50f5d2e27b4064c576cd11d59469c6cd7d2a5d75577f55065a135e907890da4246f5ee658b866c9fbdb30973956a
6
+ metadata.gz: 50dd554e11fccd5775d4be9da95aac13baf6e6eea07668d346940ad76ab26a2e3a950e288f974eb515088c53746adc6e01eb4123029eb7e0fb737871d4d3bc7b
7
+ data.tar.gz: 3ca3093dec8e3873b6986ff8cd073acb8134908a070129bd178a7a1f6229a19675718b14bdb1e063cf3aef332131968893211fa32fadc375f34569107bc8be4d
@@ -14,7 +14,13 @@ structure do
14
14
  end
15
15
 
16
16
  section :hobbies do
17
- pointlist :info
17
+ list :points
18
+ end
19
+
20
+ section :other do
21
+ list :things do
22
+ string :name, :description
23
+ end
18
24
  end
19
25
  end
20
26
 
@@ -33,14 +39,29 @@ data do
33
39
  end
34
40
 
35
41
  skills do
36
- things %{foo bar baz qux}
42
+ thing %{foo bar baz qux}
37
43
  end
38
44
 
39
45
  hobbies do
40
- info do
41
- point 'Reading about Haskell'
42
- point 'Evangelizing monads'
43
- point 'Making beer'
46
+ point 'Reading about Haskell'
47
+ point 'Evangelizing monads'
48
+ point 'Making beer'
49
+ end
50
+
51
+ other do
52
+ thing do
53
+ name 'foo'
54
+ description 'foo desc'
55
+ end
56
+
57
+ thing do
58
+ name 'bar'
59
+ description 'bar desc'
60
+ end
61
+
62
+ thing do
63
+ name 'baz'
64
+ description 'baz desc'
44
65
  end
45
66
  end
46
67
  end
@@ -1,6 +1,6 @@
1
1
  <ul>
2
- <% info.points.each do |point| %>
3
- <li><%= point %></li>
2
+ <% points.each do |p| %>
3
+ <li><%= p %></li>
4
4
  <% end %>
5
5
  </ul>
6
6
 
@@ -1 +1 @@
1
- <div><%= things.join(' / ') %></div>
1
+ <div><%= things.join(' // ') %></div>
@@ -16,6 +16,9 @@
16
16
  <div class="section">
17
17
  <%= render_section(:hobbies) %>
18
18
  </div>
19
+ <div class="section">
20
+ <%= render_section(:other) %>
21
+ </div>
19
22
  </body>
20
23
  </html>
21
24
 
@@ -1,5 +1,4 @@
1
1
  require 'thor'
2
- require 'active_support/inflector'
3
2
 
4
3
  module Resulang
5
4
  class Exec < Thor
@@ -1,3 +1,5 @@
1
+ require 'active_support/inflector'
2
+
1
3
  module Resulang
2
4
  module Fields
3
5
  def self.included(base)
@@ -10,24 +12,6 @@ module Resulang
10
12
  class Link < String
11
13
  end
12
14
 
13
- class PointList
14
- attr_reader :points
15
-
16
- def initialize(string: nil, &block)
17
- @string = string
18
- @points = [ ]
19
- instance_eval(&block) if block
20
- end
21
-
22
- def point(string, &block)
23
- points.push(PointList.new(string: string, &block))
24
- end
25
-
26
- def to_s
27
- @string
28
- end
29
- end
30
-
31
15
  module ClassMethods
32
16
  protected def string(*attrs)
33
17
  fields(*attrs) { |value| value }
@@ -41,18 +25,36 @@ module Resulang
41
25
  fields(*attrs) { |value| Link.new(value) }
42
26
  end
43
27
 
44
- protected def list(*attrs)
45
- fields(*attrs) { |value| Array(value) }
28
+ protected def list(*attrs, &item_decl)
29
+ attrs.each do |name|
30
+ define_method(name) do |*args, &block|
31
+ field_get(name)
32
+ end
33
+
34
+ singular = ActiveSupport::Inflector.singularize(name)
35
+
36
+ define_method(singular) do |*args, &item_def|
37
+ if args.empty? && item_def.nil?
38
+ raise "no arguments or definition block given for list #{singular}"
39
+ end
40
+
41
+ items = field_get(name) || []
42
+
43
+ if item_def.nil?
44
+ args.each { |a| items.push(a) }
45
+ elsif
46
+ items.push(Class.new(Section, &item_decl).new(name: name, &item_def))
47
+ end
48
+
49
+ field_set(name, items)
50
+ end
51
+ end
46
52
  end
47
53
 
48
54
  protected def range(*attrs)
49
55
  fields(*attrs) { |*values| (values.first..values.last) }
50
56
  end
51
57
 
52
- protected def pointlist(*attrs)
53
- fields(*attrs) { |&block| PointList.new(&block) }
54
- end
55
-
56
58
  private def fields(*names, &block)
57
59
  names.each do |name|
58
60
  define_method(name) do |*args, &b|
@@ -1,5 +1,3 @@
1
- require 'active_support/inflector'
2
-
3
1
  module Resulang
4
2
  class Section
5
3
  attr_reader :name
@@ -1,3 +1,3 @@
1
1
  module Resulang
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resulang
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Brindisi