mumukit-directives 0.3.0 → 0.3.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
- SHA1:
3
- metadata.gz: 9a280f1e9058510755e7d158fa3613f0981d8360
4
- data.tar.gz: 11a593e18b61e6018fa914f12b04ffa4bacf6838
2
+ SHA256:
3
+ metadata.gz: 9d404944c578e7a56d745cbdf8adf110599ef29c07954aff201f36469694c092
4
+ data.tar.gz: dc3ce9797fbd0923b3726760d1800afa119260e28d96051dd1af67b288d022cf
5
5
  SHA512:
6
- metadata.gz: cd74c24ad653451b3fc67df9dd1df9102ab4cc7eff25cfd3367890549cbeb083f119dfb86b281733334922fd521ee0c05f119ce84e820d59e7943d6c18bb6106
7
- data.tar.gz: 9858d10a4a2587159aaf8e0abe4525e72cd71bee56cde189c29ce8380d539a5a7f1546386c5e883727393d2f678064dc769c957532f7084cc614c4a65ce917a5
6
+ metadata.gz: 9ab936fc6db1450368d3f1230a71d96ba400bd085287f6b0f3efc00ee723b5e75bdc7681a030a1eb2e81dd8a4e2d5a8a95f7d352826c569699a8f3fe30c5cc30
7
+ data.tar.gz: d044ed922a7ffe9dc8c3198d30b3aed7c277e535ad39cec94509721e844cdc617953d2c2d717f199778985f4d1f146e004c357494c291f0884a89f6a964a513b
@@ -2,21 +2,38 @@ module Mumukit::Directives::CommentType
2
2
  def self.parse(string)
3
3
  case string
4
4
  when 'ruby' then
5
- Mumukit::Directives::Ruby
5
+ Ruby
6
6
  when 'haskell' then
7
- Mumukit::Directives::Haskell
7
+ Haskell
8
8
  else
9
- Mumukit::Directives::Cpp
9
+ Cpp
10
10
  end
11
11
  end
12
12
 
13
+ module Comment
14
+ def comment(code)
15
+ "#{open}#{code}#{close}"
16
+ end
17
+
18
+ def open_comment
19
+ Regexp.new Regexp.escape(open)
20
+ end
21
+
22
+ def close_comment
23
+ Regexp.new Regexp.escape(close)
24
+ end
25
+
26
+ end
27
+
13
28
  module Cpp
14
- def self.open_comment
15
- /\/\*/
29
+ extend Comment
30
+
31
+ def self.open
32
+ '/*'
16
33
  end
17
34
 
18
- def self.close_comment
19
- /\*\//
35
+ def self.close
36
+ '*/'
20
37
  end
21
38
 
22
39
  def self.to_s
@@ -25,12 +42,14 @@ module Mumukit::Directives::CommentType
25
42
  end
26
43
 
27
44
  module Ruby
28
- def self.open_comment
29
- /#/
45
+ extend Comment
46
+
47
+ def self.open
48
+ '#'
30
49
  end
31
50
 
32
- def self.close_comment
33
- /#/
51
+ def self.close
52
+ '#'
34
53
  end
35
54
 
36
55
  def self.to_s
@@ -39,12 +58,14 @@ module Mumukit::Directives::CommentType
39
58
  end
40
59
 
41
60
  module Haskell
42
- def self.open_comment
43
- /\{-/
61
+ extend Comment
62
+
63
+ def self.open
64
+ '{-'
44
65
  end
45
66
 
46
- def self.close_comment
47
- /-\}/
67
+ def self.close
68
+ '-}'
48
69
  end
49
70
 
50
71
  def self.to_s
@@ -9,4 +9,4 @@ class Mumukit::Directives::Directive
9
9
  @comment_type ||= Mumukit::Directives::CommentType::Cpp
10
10
  end
11
11
 
12
- end
12
+ end
@@ -1,5 +1,5 @@
1
1
  class Mumukit::Directives::Interpolations < Mumukit::Directives::Directive
2
- def initialize(key)
2
+ def initialize(key=nil)
3
3
  @key = key
4
4
  end
5
5
 
@@ -15,14 +15,20 @@ class Mumukit::Directives::Interpolations < Mumukit::Directives::Directive
15
15
  interpolated = []
16
16
 
17
17
  var = code.captures(comment_regexp) do
18
- interpolated << $1
19
- sections[$1]
18
+ substitution = sections[$1]
19
+ if substitution
20
+ interpolated << $1
21
+ substitution
22
+ else
23
+ $&
24
+ end
20
25
  end
21
26
 
22
27
  [var, interpolated.uniq]
23
28
  end
24
29
 
25
30
  def transform(sections)
31
+ raise 'Missing key. Build the interpolations with a key in order to use this method' unless @key
26
32
  code = sections[@key]
27
33
  if interpolations? code
28
34
  interpolation, interpolated = interpolate code, sections.except(@key)
@@ -1,6 +1,6 @@
1
1
  class Mumukit::Directives::Sections < Mumukit::Directives::Directive
2
2
  def regexp
3
- /<(.+?)##{comment_type.close_comment}(.+?)#{comment_type.open_comment}#(.+?)>/
3
+ /<(.+?)##{comment_type.close_comment}(.+?)#{comment_type.open_comment}#(.+?)>/m
4
4
  end
5
5
 
6
6
  def split_sections(code)
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Directives
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
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.0
4
+ version: 0.3.1
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-07-25 00:00:00.000000000 Z
11
+ date: 2017-12-06 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.4.5
127
+ rubygems_version: 2.7.3
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Interpolations, sections and flags pipelines for mumuki