trekky 0.0.7.rc2 → 0.0.7.rc3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d5f9b824ded8ee28bd1cef4ca114710241778f5
4
- data.tar.gz: 4aaeeb8cec59c5708eef3914264fc320a4331b38
3
+ metadata.gz: b1b9aec1a5d263db19517c2dbae4a6b8860c16fb
4
+ data.tar.gz: eb8d218d698a83f6def8f82c8769c6151791a063
5
5
  SHA512:
6
- metadata.gz: 2fb6b1f52cf932316ee027212f1d5cd202ef795fe872089d0e96657b6e238639521f6817c64c9217a5f0a88a88cc27e04093ddbcd5368a2c2186d96d0e23fcc0
7
- data.tar.gz: 2b6a87258df488138dff2e5c3f00b5a90cb32268a5e27ea155f259bd92bf33635aa0d10f3d145dc4cf711e1fa49ab927ba6af0f0011bff4fdc799a64c086dbe4
6
+ metadata.gz: 439ce4280105f0ce47a4e2aa070f9c23dacd60b1a768282c972930e9e29b2def2a49d1a45d7f61ccbde3c3d2701993070bda890fae311626155a86e932c4bf44
7
+ data.tar.gz: fbcd0e90819f05fdde98d4f42ca404ad1b076d34c4c21feb3e317cc9e82cb547dd76f4384adb1841875a53d236045350a1395405c06c54c276ac06ce1b6a7276
@@ -5,6 +5,7 @@ class Trekky
5
5
 
6
6
  def initialize(source_dir)
7
7
  @context = Context.new(source_dir)
8
+
8
9
  if File.exists?(config_file)
9
10
  STDOUT.puts "Loading config file: #{config_file}"
10
11
  require config_file
@@ -1,6 +1,7 @@
1
+ require_relative 'data'
1
2
  require_relative 'haml_source'
2
- require_relative 'static_source'
3
3
  require_relative 'sass_source'
4
+ require_relative 'static_source'
4
5
 
5
6
  class Trekky
6
7
  class Context
@@ -29,6 +30,10 @@ class Trekky
29
30
  partials.find {|p| p.path == File.join(source_dir, name)}
30
31
  end
31
32
 
33
+ def data
34
+ @data ||= Data.new(data_path)
35
+ end
36
+
32
37
  private
33
38
 
34
39
  def build
@@ -65,5 +70,10 @@ class Trekky
65
70
  { sass: SassSource, haml: HamlSource }
66
71
  end
67
72
 
73
+ def data_path
74
+ File.join(Dir.pwd, 'data')
75
+ end
76
+
77
+
68
78
  end
69
79
  end
@@ -0,0 +1,56 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+
4
+ class Trekky
5
+ class Data
6
+
7
+ class DeepStruct < OpenStruct
8
+
9
+ def initialize(hash=nil)
10
+ @table = {}
11
+ @hash_table = {}
12
+
13
+ if hash
14
+ hash.each do |k,v|
15
+ @table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
16
+ @hash_table[k.to_sym] = v
17
+
18
+ new_ostruct_member(k)
19
+ end
20
+ end
21
+ end
22
+
23
+ def to_h
24
+ @hash_table
25
+ end
26
+
27
+ end
28
+
29
+ def initialize(path)
30
+ @path = path
31
+ @data = Hash.new
32
+ super()
33
+ end
34
+
35
+ def method_missing(method_name, *args)
36
+ if @data.has_key?(method_name)
37
+ @data[method_name]
38
+ else
39
+ @data[method_name] = load_data(method_name)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def load_data(name)
46
+ yaml = YAML.load_file(File.join(@path, "#{name}.yml"))
47
+ if yaml.respond_to?(:each)
48
+ yaml.map { |y| DeepStruct.new(y) }
49
+ else
50
+ DeepStruct.new(yaml)
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -10,6 +10,10 @@ class Trekky
10
10
  @errors = []
11
11
  end
12
12
 
13
+ def data
14
+ @context.data
15
+ end
16
+
13
17
  def render(&block)
14
18
  raise NotImplementedError
15
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trekky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.rc2
4
+ version: 0.0.7.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Florio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clap
@@ -78,6 +78,7 @@ files:
78
78
  - bin/trekky
79
79
  - lib/trekky.rb
80
80
  - lib/trekky/context.rb
81
+ - lib/trekky/data.rb
81
82
  - lib/trekky/haml_source.rb
82
83
  - lib/trekky/sass_source.rb
83
84
  - lib/trekky/source.rb