datagnan 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datagnan.rb +18 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05607710b99a729b6621ee1ed606791acca3d926
4
- data.tar.gz: 19fe21526067a3c30121ff0548f788ebd2d2db76
3
+ metadata.gz: 51727d19fe0ccfcc902d890b88206a1183e39ccb
4
+ data.tar.gz: 6fd8ef869f5545f1f273a5d27d9cf921e2492b5e
5
5
  SHA512:
6
- metadata.gz: d20055d75d94aac632aebeaf7f443c620a68477d1c999993a44a7f8e9674502b2352116bf0da9aaf1515966c548358fa4110a6f1bd00b38bf5fd863cb2ee1cd4
7
- data.tar.gz: fc27c125b3c574a2a82074b95bea1e633f83ae7f673475d24be93b22dcf055ba737ab443da67fef1ae1e7f356184a0ec5dcd44c79664c8daf9d8f89f4cde8183
6
+ metadata.gz: 9a8b138290a6c01440e21ec088aefc04c54f91850fc1af35f98e43507c4df24dc809a8c5b872a528fb77c28d5aacad12b2c70017c04c170d3deba0a801bc0621
7
+ data.tar.gz: 2459f8e06704ee97e6e6d645348906dcc321c1fc5afc2f5cefc559c843d1af3c14707ef445f180bb54ecd3e3806f81cfad62607b3e1b1a68ebb50068a31ec417
@@ -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! local_vars
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
- node.children = Oga.parse_html(var.to_s).children
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 = find_value(node.get('data-when-not'), vars)
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] ||= {}).merge! 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
- options[:local_vars]['template'] = { 'html' => html }
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
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-26 00:00:00.000000000 Z
12
+ date: 2015-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oga