datagnan 1.2.4 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datagnan.rb +18 -8
- 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: 51727d19fe0ccfcc902d890b88206a1183e39ccb
|
4
|
+
data.tar.gz: 6fd8ef869f5545f1f273a5d27d9cf921e2492b5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a8b138290a6c01440e21ec088aefc04c54f91850fc1af35f98e43507c4df24dc809a8c5b872a528fb77c28d5aacad12b2c70017c04c170d3deba0a801bc0621
|
7
|
+
data.tar.gz: 2459f8e06704ee97e6e6d645348906dcc321c1fc5afc2f5cefc559c843d1af3c14707ef445f180bb54ecd3e3806f81cfad62607b3e1b1a68ebb50068a31ec417
|
data/lib/datagnan.rb
CHANGED
@@ -20,7 +20,7 @@ class Datagnan
|
|
20
20
|
@options[:attrs_sep] = options[:attrs_sep] || ";"
|
21
21
|
@options[:path_filters] = options[:path_filters] || {}
|
22
22
|
@scope = options[:scope] || self
|
23
|
-
@vars = (options[:local_vars] || {}).merge
|
23
|
+
@vars = (options[:local_vars] || {}).merge local_vars
|
24
24
|
@vars.merge! Hash[@scope.instance_variables.map { |name| [name.to_s, @scope.instance_variable_get(name)] } ] unless @scope.nil?
|
25
25
|
## debug
|
26
26
|
# puts "-- Datagnan.new ( @vars = #{@vars} )"
|
@@ -188,7 +188,11 @@ private
|
|
188
188
|
var = find_value(node.get('data-var'), vars)
|
189
189
|
|
190
190
|
unless var.nil?
|
191
|
-
|
191
|
+
begin
|
192
|
+
node.children = Oga.parse_html(var.to_s).children
|
193
|
+
rescue
|
194
|
+
node.inner_text = var.to_s
|
195
|
+
end
|
192
196
|
node.unset('data-var')
|
193
197
|
end
|
194
198
|
## TODO: if var not exist remember it (maybe return to model)
|
@@ -346,10 +350,16 @@ private
|
|
346
350
|
# puts "Datagnan.data_when_not ( root = #{root} )"
|
347
351
|
root.css('*[data-when-not]').each do |node|
|
348
352
|
|
349
|
-
var =
|
353
|
+
var = node.get('data-when-not').split(@options[:attrs_sep]).each do |key|
|
354
|
+
## debug
|
355
|
+
# puts "-- Datagnan.data_when_not each split ( key = #{key} )"
|
356
|
+
var = find_value(key, vars)
|
357
|
+
# puts "-- Datagnan.data_when_not each split ( var = #{var} )"
|
358
|
+
break var unless var
|
359
|
+
end
|
350
360
|
|
351
361
|
## allow for nil
|
352
|
-
var ? node.remove : node.unset('data-when')
|
362
|
+
var ? node.remove : node.unset('data-when-not')
|
353
363
|
## TODO: if var not exist remember it (maybe return to model)
|
354
364
|
end
|
355
365
|
## debug
|
@@ -371,7 +381,7 @@ def datagnan(template_files, options = {}, local_vars = {})
|
|
371
381
|
options[:scope] ||= self
|
372
382
|
options[:views_dir] = File.realpath(options[:views_dir] || (options[:scope].settings.views if options[:scope].respond_to? :settings) || "./views")
|
373
383
|
options[:layout_file] = File.join(options[:views_dir], options[:layout_file] || 'layout.html')
|
374
|
-
(options[:local_vars]
|
384
|
+
vars = (options[:local_vars] || {}).merge local_vars
|
375
385
|
|
376
386
|
html = ""
|
377
387
|
template_files = [template_files] unless template_files.is_a? Array
|
@@ -381,15 +391,15 @@ def datagnan(template_files, options = {}, local_vars = {})
|
|
381
391
|
template_file += '.html' unless File.exist? template_file
|
382
392
|
|
383
393
|
## render template
|
384
|
-
html += Datagnan.read(template_file, options)
|
394
|
+
html += Datagnan.read(template_file, options, vars)
|
385
395
|
## debug
|
386
396
|
# puts "-- datagnan ( template = #{html} )"
|
387
397
|
end
|
388
398
|
|
389
399
|
## check for layout and wrap template if exist
|
390
400
|
if File.exist? options[:layout_file]
|
391
|
-
|
392
|
-
html = Datagnan.read(options[:layout_file], options)
|
401
|
+
vars['template'] = { 'html' => html }
|
402
|
+
html = Datagnan.read(options[:layout_file], options, vars)
|
393
403
|
## debug
|
394
404
|
# puts "-- datagnan ( layout = #{html} )"
|
395
405
|
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.2.
|
4
|
+
version: 1.2.5
|
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
|
+
date: 2015-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oga
|