thot 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/thot.rb +32 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bc290fd549f5d8f74f3976bf295caf1948c4034c6b70b6d611481a9062d6192
4
- data.tar.gz: af1047cf61a5570eb1fdb6981689bbc099fd0c01455401a6842d951b36f001f9
3
+ metadata.gz: 7a6bb1b17f33806eecd83ba7697b0e66a311772fdf0b368cfc307bddf6c74ee3
4
+ data.tar.gz: 12cba548403a8cf9ab2edee54a7a8f4567bd612367b798a3138468c185462b59
5
5
  SHA512:
6
- metadata.gz: b8d2156265be4a1f7521a2a05a9f928e1016e059c55451c4d7f7bc76022f7390888e8361ed6daee4111972b974c0eb06b9b2859767c28d9c8bfbdb15794ff5c0
7
- data.tar.gz: cc24897736a165ee81c3e8f38ba81e5d1926768192ad08c938664e18145a2a16f00a57aa0bb3772745476a63d2c0a77b2623d1a03ba72d77c7c5c6380b036c61
6
+ metadata.gz: 73592234300f96931e105eab69a0dfa71b6817e23e12736485c1529b8105af86fe8765a585b80b2ca950a206661e78f8d625433de8c98b9d054b97cb94ac43e4
7
+ data.tar.gz: 22236a2db50ad40e55761e24068788a8b17f6356bff00050b6b40263f708c3015979a35e6e4e9c3c4b54341f9a7d4df2088c2b8836dc04822c3051dbc7e5cd39
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 1.0.0
data/lib/thot.rb CHANGED
@@ -19,7 +19,7 @@ module Thot
19
19
  # constructor : generate the pseudo accessor for template Class from token list
20
20
  def initialize(template_file: , list_token: , strict: true)
21
21
 
22
-
22
+ @result = ""
23
23
  @template_file = template_file
24
24
  raise NoTemplateFile::new('No template file found') unless File::exist?(@template_file)
25
25
  begin
@@ -39,8 +39,13 @@ module Thot
39
39
  else
40
40
  raise InvalidTokenList::new("Token list doesn't match the template") unless (token_from_template.sort & @list_token.sort) == token_from_template.sort
41
41
  end
42
- @list_token.each{|_token| eval("def #{_token}=(_value); raise ArgumentError::new('Not a String') unless _value.class == String; @hash_token['#{_token}'] = _value ;end")}
43
- @list_token.each{|_token| eval("def #{_token}; @hash_token['#{_token}'] ;end")}
42
+ @list_token.each do |_token|
43
+ self.instance_eval do
44
+ define_singleton_method(:"#{_token}=") {|_value| raise ArgumentError::new('Not a String') unless _value.class == String; @hash_token[__callee__.to_s.chomp('=')] = _value }
45
+ define_singleton_method(_token.to_sym) { return @hash_token[__callee__.to_s] }
46
+ end
47
+ end
48
+
44
49
  end
45
50
 
46
51
  # generic accessor
@@ -73,14 +78,31 @@ module Thot
73
78
  # the templater;proceed to templating
74
79
  # @return [String] the template output
75
80
  def output
76
- _my_res = String::new('')
77
- _my_res = @content
81
+ @result = @content
78
82
  @list_token.each{|_token|
79
- _my_res.gsub!(/%%#{_token.to_s.upcase}%%/,@hash_token[_token.to_s])
83
+ self.filtering @content.scan(/%%(#{_token.to_s.upcase}[\.\w+]+)%%/).flatten
84
+ @result.gsub!(/%%#{_token.to_s.upcase}%%/,@hash_token[_token.to_s])
80
85
  }
81
- return _my_res
86
+ return @result
87
+ end
88
+
89
+ private
90
+
91
+ def filtering(list)
92
+ @filtered_tokens = {}
93
+ list.each do |pipe|
94
+ token, *filters = pipe.split('.')
95
+ @filtered_tokens[pipe] = @hash_token[token.downcase]
96
+ filters.each do |filter|
97
+ @filtered_tokens[pipe] = @filtered_tokens[pipe].send filter.to_sym if @filtered_tokens[pipe].respond_to? filter.to_sym
98
+ end
99
+ end
100
+ @filtered_tokens.each do |item,value|
101
+ @result.gsub!(/%%#{item}%%/,value)
102
+ end
82
103
  end
83
104
 
105
+
84
106
  end
85
107
 
86
108
  # Exception for an invalid Token list
@@ -91,3 +113,6 @@ module Thot
91
113
  class NoTemplateFile < Exception; end
92
114
 
93
115
  end
116
+
117
+
118
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-15 00:00:00.000000000 Z
11
+ date: 2022-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake