mumukit-directives 0.3.2 → 0.4.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
  SHA256:
3
- metadata.gz: a8a5966b95ea84427cffe98787f81a2c19fb798b39e9716b44118f9588d6147d
4
- data.tar.gz: f985b9287e338a688d23ea6a7520f3b8a16f86fcdac147e98943c1a6de0e6809
3
+ metadata.gz: a96803a6b78cfe143f001aa01776f1c8433f2f175d9bda40bda8e79a052024ef
4
+ data.tar.gz: 1d3379588b8f0fa1cbd403c4677ea018a2ecf785da2c2b8e584bc15998daac89
5
5
  SHA512:
6
- metadata.gz: e5427919f12690e7fd33086a61741038a0fc011f42a9a5f102c2452eb7d2bd302fdfe737d58cdac9e1ddd4984eebe5e582203c402d06efaeff80144bddafbbd1
7
- data.tar.gz: 8cd06b2fd23f06ff8a24a2db1edb9ed25364544d071e489f7ce1a75bfdd114f5a05957a70338c175a9582efbd3a2fda4ce0f21a881a173054e7d0d9e2210a8c2
6
+ metadata.gz: bbbf5de2ffe4e812e3439007f9ea6e2154db87db5ef02b32fa1b35bbfdc678ded0a52a3de6d1a0ea063f5386c2aaf8565eb4da380e598a9b1a5c01dbec67d855
7
+ data.tar.gz: 8ace2a2100ef4da408d3bab91a227c520b759403a167ac70970ce086b1a47e1b431df6f7a367ef91ce71443b70b5da89b5816f7b2c51cb00e401480a107ab47a
@@ -9,7 +9,7 @@ class Mumukit::Directives::Pipeline
9
9
  rest = base_sections.slice!('test', 'extra', 'content', 'query')
10
10
 
11
11
  @directives
12
- .inject(base_sections) { |sections, it| it.transform(sections) }
12
+ .inject(base_sections) { |sections, it| it.transform sections }
13
13
  .amend(rest)
14
14
  .to_struct
15
15
  end
@@ -1,4 +1,41 @@
1
+ # `Sections` directive allows code to be splitted into
2
+ # zero or more parts, using markup-like delimiter.
3
+ #
4
+ # The transformed result is a hash that replaces the
5
+ # key's content with the included sections. For example, if the `extra`
6
+ # key has two sections `foo` and `bar`...
7
+ #
8
+ # ```
9
+ # # Input
10
+ # { extra: 'foo /*<baz#*/lalala/*#baz>*/ ignored /*<bar#*/lelele/*#bar>*/' }
11
+ # ```
12
+ #
13
+ # ... the resultant hash will contain
14
+ # the `foo` and `bar` keys, and no `extra` key:
15
+ #
16
+ # ```
17
+ # # Output
18
+ # { baz: 'lalala', bar: 'lelele' }
19
+ # ```
20
+ #
21
+ # Alternatively, if the `nest_sections` option is enabled...
22
+ #
23
+ # ```
24
+ # Mumukit::Directives::Sections.new nest_sections: true
25
+ # ```
26
+ #
27
+ # ...instead of replacing the original parent section, the new child sections are nested into it:
28
+ #
29
+ # ```
30
+ # # Output
31
+ # { extra: { baz: 'lalala', bar: 'lelele' } }
32
+ # ```
33
+
1
34
  class Mumukit::Directives::Sections < Mumukit::Directives::Directive
35
+ def initialize(options={})
36
+ @nest_sections = !!options[:nest_sections]
37
+ end
38
+
2
39
  def regexp
3
40
  /<(.+?)##{comment_type.close_comment}(.*?)#{comment_type.open_comment}#(.+?)>/m
4
41
  end
@@ -13,13 +50,28 @@ class Mumukit::Directives::Sections < Mumukit::Directives::Directive
13
50
  def transform(sections)
14
51
  result = {}
15
52
  sections.each do |key, code|
16
- new_sections = split_sections(code)
17
- if new_sections.present?
18
- result.merge!(new_sections)
19
- else
20
- result[key] = code
21
- end
53
+ merge_sections! result, key, code, split_sections(code)
22
54
  end
23
55
  result
24
56
  end
57
+
58
+ private
59
+
60
+ def merge_sections!(result, key, code, new_sections)
61
+ if new_sections.blank?
62
+ result[key] = code
63
+ elsif @nest_sections
64
+ merge_parent_key! result, key, new_sections
65
+ else
66
+ merge_child_keys! result, key, new_sections
67
+ end
68
+ end
69
+
70
+ def merge_child_keys!(result, key, new_sections)
71
+ result.merge! new_sections
72
+ end
73
+
74
+ def merge_parent_key!(result, key, new_sections)
75
+ result[key] = new_sections
76
+ end
25
77
  end
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Directives
3
- VERSION = '0.3.2'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumukit-directives
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-06 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 2.7.3
127
+ rubygems_version: 2.7.7
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Interpolations, sections and flags pipelines for mumuki