tzispa_rig 0.2.4 → 0.2.5

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
  SHA1:
3
- metadata.gz: 67a97fb9282f8c87d0db417f38f280df6928d810
4
- data.tar.gz: 75b52c0b2ca111bdb9c3445ce8f329b9e99dd910
3
+ metadata.gz: aef6c491f3383fc7cbd791222d9a35f5ba1503ed
4
+ data.tar.gz: 75e0bc0bbf5d889882d886645c283027c6180575
5
5
  SHA512:
6
- metadata.gz: dc4014b2a90e3424150252dbcb947ee9c84081d6e2948b1b3b1816c3732f24c4301b91dcb47f62a4709b1cb3917c8a80d6e0c218b141ec9b4ebc44c3957a9f6c
7
- data.tar.gz: d3f5b7bbbf52c665b3b0e6642fc5e020ae2eaf5d39d7786c8cea3dacb66b6247c7b7813c663087ab1a6d8a67230fc5c26ed5a101359ad01c5d26b0cba3714377
6
+ metadata.gz: 071b901ee6482b8609a743688dc4fd9a1c996d124522c75e91ee2109f5a95887a1e5fab41ec6eccfb7541238d018ff6e48afc66658859cc5e739baf605432794
7
+ data.tar.gz: 87e18aaae6a446409b51dfcd3943845819786457696742277cc6ffac45c042d58a116f236c3b7a463f9f9f59d24a49633807ae414536ebb185fa7066d8f64963
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@ Tzispa Rig
2
2
 
3
3
  Rig templates implementation
4
4
 
5
+ ## v0.2.5
6
+ - Add template methods for use in cli
7
+
8
+ ## v0.2.4
9
+ - allow loop_item binder without parameters
10
+
5
11
  ## v0.2.3
6
12
  - Fix in the api call regex syntax
7
13
  - Added prefix in api calls
@@ -96,11 +96,11 @@ module Tzispa
96
96
  @source_object.send method, *args, &generator
97
97
  end
98
98
 
99
- def loop_item(**params)
99
+ def loop_item(params=nil)
100
100
  (LoopItem.new self).tap { |item|
101
101
  params.each{ |k,v|
102
102
  item.data[k] = v
103
- }
103
+ } if params
104
104
  }
105
105
  end
106
106
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
- require 'tzispa/domain'
5
4
  require 'tzispa/utils/string'
6
5
 
7
6
 
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'forwardable'
4
+ require 'fileutils'
5
+ require 'tzispa/utils/string'
6
+ require 'tzispa/rig'
7
+
3
8
  module Tzispa
4
9
  module Rig
5
10
 
@@ -24,13 +29,13 @@ module Tzispa
24
29
  @modified != File.mtime(@file)
25
30
  end
26
31
 
27
- def exists?
28
- ::File.exists?(@file)
32
+ def exist?
33
+ ::File.exist?(@file)
29
34
  end
30
35
 
31
36
  def load!
32
37
  begin
33
- raise NotFound.new("Template file '#{@file}' not found") unless exists?
38
+ raise NotFound.new("Template file '#{@file}' not found") unless exist?
34
39
  ::File.open(@file, 'r:UTF-8') { |f|
35
40
  @content = String.new
36
41
  @modified = f.mtime
@@ -45,6 +50,12 @@ module Tzispa
45
50
  self
46
51
  end
47
52
 
53
+ def create(content=nil)
54
+ ::File.open(@file, "w") { |f|
55
+ f.puts content
56
+ }
57
+ end
58
+
48
59
  end
49
60
 
50
61
 
@@ -73,8 +84,7 @@ module Tzispa
73
84
  @domain = domain
74
85
  @format = format || DEFAULT_FORMAT
75
86
  end
76
- raise ArgumentError.new('Missing parameter(s): domain and engine must be especified') unless @domain && @engine
77
- super "#{@domain.path}/rig/#{@type.to_s.downcase}/#{@subdomain+'/' if @subdomain}#{@name}.#{RIG_EXTENSION}.#{@format}"
87
+ super "#{path}/#{@name}.#{RIG_EXTENSION}.#{@format}"
78
88
  end
79
89
 
80
90
  def parse!
@@ -90,6 +100,17 @@ module Tzispa
90
100
  @parser.render binder, context
91
101
  end
92
102
 
103
+ def path
104
+ "#{@domain.path}/rig/#{@type.to_s.downcase}#{'/'+@subdomain if @subdomain}"
105
+ end
106
+
107
+ def create
108
+ FileUtils.mkdir_p(path) unless Dir.exist? path
109
+ puts "path = #{Dir.exist? path}"
110
+ super
111
+ create_binder
112
+ end
113
+
93
114
  def is_block?
94
115
  @type == :block
95
116
  end
@@ -110,9 +131,21 @@ module Tzispa
110
131
  @params.data
111
132
  end
112
133
 
134
+ def binder_require
135
+ "rig/#{@type}/#{@subdomain+'/' if @subdomain}#{@name.downcase}"
136
+ end
137
+
138
+ def binder_namespace
139
+ "#{TzString.camelize @domain.name}::Rig::#{@type.to_s.capitalize}#{'::' + TzString.camelize(@subdomain) if @subdomain}"
140
+ end
141
+
142
+ def binder_class_name
143
+ TzString.camelize @name
144
+ end
145
+
113
146
  def binder_class
114
- @domain.require "rig/#{@type}/#{@subdomain+'/' if @subdomain}#{@name.downcase}"
115
- TzString.constantize "#{TzString.camelize @domain.name}::Rig::#{@type.to_s.capitalize}::#{TzString.camelize(@subdomain+'::') if @subdomain}#{TzString.camelize @name }"
147
+ @domain.require binder_require
148
+ TzString.constantize "#{binder_namespace}::#{binder_class_name}"
116
149
  end
117
150
 
118
151
  private
@@ -122,6 +155,25 @@ module Tzispa
122
155
  @type = value
123
156
  end
124
157
 
158
+ def create_binder
159
+ ::File.open("#{domain.path}/#{binder_require}.rb", "w") { |f|
160
+ binder_code = TzString.new
161
+ f.puts binder_code.indenter("require 'tzispa/rig/binder'\n\n")
162
+ level = 0
163
+ binder_namespace.split('::').each { |ns|
164
+ f.puts binder_code.indenter("module #{ns}\n", level > 0 ? 2 : 0).to_s
165
+ level += 1
166
+ }
167
+ f.puts binder_code.indenter("\nclass #{binder_class_name} < Tzispa::Rig::TemplateBinder\n\n", 2)
168
+ f.puts binder_code.indenter("def bind!", 2)
169
+ f.puts binder_code.indenter("end\n\n")
170
+ f.puts binder_code.unindenter("end", 2)
171
+ binder_namespace.split('::').each { |ns|
172
+ f.puts binder_code.unindenter("end\n", 2)
173
+ }
174
+ } if @type == :block
175
+ end
176
+
125
177
  end
126
178
 
127
179
 
@@ -3,8 +3,8 @@
3
3
  module Tzispa
4
4
  module Rig
5
5
 
6
- VERSION = '0.2.4'.freeze
7
- GEM_NAME = 'tzispa_rig'.freeze
6
+ VERSION = '0.2.5'
7
+ GEM_NAME = 'tzispa_rig'
8
8
 
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_rig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Antonio Piñero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzispa_helpers
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: 0.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
26
+ version: 0.1.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tzispa_utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: 0.2.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: 0.2.1
41
41
  description: General purpose template engine
42
42
  email:
43
43
  - japinero@area-integral.com
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.5.1
78
+ rubygems_version: 2.4.8
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: General purpose template engine