jsontemplate 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c6bb416c8e7f40f34ce5b4d98cf739dd2e63ba2
4
+ data.tar.gz: a3d9d6d43d1f0f06d93c676433409a86a0f86e00
5
+ SHA512:
6
+ metadata.gz: 6380a11c7a4cca159cb8f7a97457cc30e86a76c78ed92820f286943889fdb577deeacd51dc067df827f0dc100f7da76288cc3bf367cd3e7763eefecae82d97d5
7
+ data.tar.gz: 84b91beaf683adebd9562088334dcb954b23bdf20ae6910d4870b350a68adcf810331ddba849750ca811703456e2942da0bbae9b7f92a56a8c68e1d8d9fddf01
data/exe/jsontemplate ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'jsontemplate'
4
+
5
+ def process_json(src)
6
+ t = JsonTemplate.new(src)
7
+ t.process_dict
8
+ end
9
+
10
+ src = File.expand_path(ARGV.shift) rescue nil
11
+ dest = File.expand_path(ARGV.shift) rescue nil
12
+
13
+ if src.nil? || dest.nil?
14
+ STDERR.puts "USAGE: jsontemplate in-file out-file"
15
+ exit(1)
16
+ end
17
+
18
+ File.open(dest,"w") do |f|
19
+ f.write(process_json(src).to_json)
20
+ end
21
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jsontemplate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jsontemplate"
8
+ spec.version = JsonTemplate::VERSION
9
+ spec.authors = ["Vidar Hokstad"]
10
+ spec.email = ["vidar@hokstadconsulting.com"]
11
+
12
+ spec.summary = %q{Simple JSON templating}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/hokstadconsulting/jsontemplate"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,3 @@
1
+ class JsonTemplate
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,40 @@
1
+ require 'json'
2
+ require "jsontemplate/version"
3
+
4
+ class JsonTemplate
5
+ def initialize(path)
6
+ @path = path
7
+ @dir = File.dirname(path)
8
+ @json = JSON.load(File.read(path))
9
+ end
10
+
11
+ def process_dirmerge(pattern)
12
+ files = Dir.glob(@dir+"/"+pattern)
13
+ files.collect do |path|
14
+ r = JsonTemplate.new(path).process_dict
15
+ key=File.basename(path).split(".")[0..-2].join(".")
16
+ [key, r]
17
+ end.flatten(1)
18
+ end
19
+
20
+ def process_dict(root=nil)
21
+ root ||= @json
22
+
23
+ pairs = root.collect do |k,v|
24
+ if v.is_a?(Hash)
25
+ v = process_dict(v)
26
+ end
27
+
28
+ if k == "$DirMerge"
29
+ process_dirmerge(v)
30
+ elsif k[0] == "$"
31
+ raise "Unknown directive #{k}"
32
+ else
33
+ [[k,v]]
34
+ end
35
+ end
36
+ Hash[*pairs.flatten(2)]
37
+ end
38
+ end
39
+
40
+
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsontemplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vidar Hokstad
@@ -11,76 +10,90 @@ bindir: exe
11
10
  cert_chain: []
12
11
  date: 2016-07-14 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ~>
31
+ - - "~>"
20
32
  - !ruby/object:Gem::Version
21
33
  version: '1.9'
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ~>
38
+ - - "~>"
28
39
  - !ruby/object:Gem::Version
29
40
  version: '1.9'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ~>
45
+ - - "~>"
36
46
  - !ruby/object:Gem::Version
37
47
  version: '10.0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ~>
52
+ - - "~>"
44
53
  - !ruby/object:Gem::Version
45
54
  version: '10.0'
46
55
  description: Simple JSON templating
47
56
  email:
48
57
  - vidar@hokstadconsulting.com
49
- executables: []
58
+ executables:
59
+ - jsontemplate
50
60
  extensions: []
51
61
  extra_rdoc_files: []
52
62
  files:
53
- - .gitignore
54
- - .rspec
55
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
56
66
  - Gemfile
57
67
  - LICENSE
58
68
  - README.md
59
69
  - Rakefile
60
70
  - bin/console
61
71
  - bin/setup
72
+ - exe/jsontemplate
73
+ - jsontemplate.gemspec
74
+ - lib/jsontemplate.rb
75
+ - lib/jsontemplate/version.rb
62
76
  homepage: https://github.com/hokstadconsulting/jsontemplate
63
77
  licenses: []
78
+ metadata: {}
64
79
  post_install_message:
65
80
  rdoc_options: []
66
81
  require_paths:
67
82
  - lib
68
83
  required_ruby_version: !ruby/object:Gem::Requirement
69
- none: false
70
84
  requirements:
71
- - - ! '>='
85
+ - - ">="
72
86
  - !ruby/object:Gem::Version
73
87
  version: '0'
74
88
  required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
89
  requirements:
77
- - - ! '>='
90
+ - - ">="
78
91
  - !ruby/object:Gem::Version
79
92
  version: '0'
80
93
  requirements: []
81
94
  rubyforge_project:
82
- rubygems_version: 1.8.23
95
+ rubygems_version: 2.6.6
83
96
  signing_key:
84
- specification_version: 3
97
+ specification_version: 4
85
98
  summary: Simple JSON templating
86
99
  test_files: []