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