datagnan 1.1.2 → 1.1.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datagnan.rb +32 -18
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5a0ec06c2a125c4ad17814577c507cc9ef89b99
4
- data.tar.gz: af543be0c33c5a149802a8b3c9029fe0f00bdd23
3
+ metadata.gz: 956fd71bee82b2660ebe07ec675371f81cdd097a
4
+ data.tar.gz: 8003be78cd8f36df3f5d209d274e65df3340ea7d
5
5
  SHA512:
6
- metadata.gz: 38bde6c095066e835795ed3950cc5fbc93990e50f60d8f786562f8f1d84a3ece6e1ac54b0c4ba5c78cab681f9e0938804f16bb10f3e224848bf81f1530f37d15
7
- data.tar.gz: bc0c93d748cd7adf1b1a9a3dc8816d5eacbf1469f35da59ff24e3cecb880c31f1a3139754fcbe120252a3311942add7cb84d98d3edcbb5fea2f631404479b421
6
+ metadata.gz: 4a74d41638671209b792ecceb88c2ac64834744d23bca7ece6c866c73b36406fcd3faa116f0422cc51a29678eda7a02dc61b6e9f90edd3f7ffe0f49ea2bc75a4
7
+ data.tar.gz: fb3b1c1409cc42c0d3b11aed7b591d85d6f6211720afb87e763bf4576ca8641cd4648a66ff995a439af39f7d02c4c502202efc674b1f1357c3ba8d7b685fb4e8
@@ -6,12 +6,15 @@ class Datagnan
6
6
  attr_accessor :doc, :vars
7
7
 
8
8
  ## Constructor
9
- # @param [String] file_path path to .html-template file
10
- # @param [Hash] options options for parsing and filling the template
9
+ # @param [String] file_path
10
+ # path to .html-template file
11
+ # @param [Hash] options
12
+ # options for parsing and filling the template
11
13
  # @option options [String] :attrs_sep (";") Separate string for 'data-attrs' attribute
12
14
  # @option options [Object] :scope (self) Scope for variables
13
15
  # @option options [Hash] :locals (locals || {}) Local variables for filling the template
14
- # @param [Hash] locals local variables for filling the template
16
+ # @param [Hash] locals
17
+ # local variables for filling the template
15
18
  def initialize(file_path, options = {}, locals = {})
16
19
  @doc = Oga.parse_html(File.read(file_path))
17
20
  ## debug
@@ -27,12 +30,15 @@ class Datagnan
27
30
  ## Create Datagnan instance and return this.
28
31
  ## Can receive implicity block for 'yield.
29
32
  ## Like File.open(file_path)
30
- # @param [String] file_path path to .html-template file
31
- # @param [Hash] options options for parsing and filling the template
33
+ # @param [String] file_path
34
+ # path to .html-template file
35
+ # @param [Hash] options
36
+ # options for parsing and filling the template
32
37
  # @option options [String] :attrs_sep (";") Separate string for 'data-attrs' attribute
33
38
  # @option options [Object] :scope (self) Scope for variables
34
39
  # @option options [Hash] :locals (locals || {}) Local variables for filling the template
35
- # @param [Hash] locals local variables for filling the template
40
+ # @param [Hash] locals
41
+ # local variables for filling the template
36
42
  def self.open(file_path, options = {}, locals = {})
37
43
  obj = Datagnan.new(file_path, options, locals).write
38
44
  yield obj if block_given?
@@ -41,12 +47,15 @@ class Datagnan
41
47
 
42
48
  ## Create Datagnan instance and return the filling with variables HTML-template as String.
43
49
  ## Like File.read(file_path)
44
- # @param [String] file_path path to .html-template file
45
- # @param [Hash] options options for parsing and filling the template
50
+ # @param [String] file_path
51
+ # path to .html-template file
52
+ # @param [Hash] options
53
+ # options for parsing and filling the template
46
54
  # @option options [String] :attrs_sep (";") Separate string for 'data-attrs' attribute
47
55
  # @option options [Object] :scope (self) Scope for variables
48
56
  # @option options [Hash] :locals (locals || {}) Local variables for filling the template
49
- # @param [Hash] locals local variables for filling the template
57
+ # @param [Hash] locals
58
+ # local variables for filling the template
50
59
  def self.read(file_path, options = {}, locals = {})
51
60
  Datagnan.new(file_path, options, locals).write.read
52
61
  end
@@ -60,8 +69,10 @@ class Datagnan
60
69
 
61
70
  ## Parse and replace
62
71
  ## Like File.new.write
63
- # @param [Hash] vars variables for filling the template
64
- # @param [Oga::XML::Document] root HTML-element for fill it
72
+ # @param [Hash] vars
73
+ # variables for filling the template
74
+ # @param [Oga::XML::Document] root
75
+ # HTML-element for fill it
65
76
  def write(vars = {}, root = nil)
66
77
  ## debug
67
78
  # puts "Datagnan.write ( vars = #{vars} )"
@@ -225,8 +236,8 @@ private
225
236
  # puts "-- Datagnan.data_each each ( node.to_xml after insert = #{node.to_xml} )"
226
237
  # puts "-- Datagnan.data_each each ( node.parent = #{node.parent.to_xml} )"
227
238
  end
228
- node.remove
229
239
  end
240
+ node.remove
230
241
  end
231
242
  end
232
243
 
@@ -269,24 +280,27 @@ private
269
280
  end
270
281
 
271
282
  ## Helper function (for Sinatra, primarily)
272
- # @param [String] file_path path to .html-template file
273
- # @param [Hash] options options for parsing and filling the template
283
+ # @param [String] file_path
284
+ # path to .html-template file
285
+ # @param [Hash] options
286
+ # options for parsing and filling the template
274
287
  # @option options [Object] :scope (self) Scope for variables
275
288
  # @option options [String] :views (scope.settings.views || "./views") Path to views directory
276
289
  # @option options [Hash] :locals (locals || {}) Local variables for filling the template
277
- # @param [Hash] locals local variables for filling the template
290
+ # @param [Hash] locals
291
+ # local variables for filling the template
278
292
  def datagnan(template_file, options = {}, locals = {})
279
293
  ## default options
280
294
  scope = options.delete(:scope) || self
281
295
  views = File.realpath(options.delete(:views) || scope.settings.views || "./views")
282
296
  locals = options.delete(:locals) || locals || {}
283
297
 
284
- html = Datagnan.read(views+'/'+template_file.to_s+'.html', :scope => scope, :locals => locals)
298
+ html = Datagnan.read(File.join(views, template_file.to_s+'.html'), :scope => scope, :locals => locals)
285
299
  ## debug
286
300
  # puts "-- datagnan ( template = #{html} )"
287
- if File.exist?(views+'/layout.html')
301
+ if File.exist? File.join(views, 'layout.html')
288
302
  locals['template'] = {'html' => html}
289
- html = Datagnan.read(views+'/layout.html', :scope => scope, :locals => locals)
303
+ html = Datagnan.read(File.join(views, 'layout.html'), :scope => scope, :locals => locals)
290
304
  ## debug
291
305
  # puts "-- datagnan ( layout = #{html} )"
292
306
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagnan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-12 00:00:00.000000000 Z
12
+ date: 2015-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oga