tree_renderer 1.0.1 → 1.1.0

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: e34039c1c00ce4efc838289475304d270b0f0cd0
4
- data.tar.gz: 63de550492c09c8e55f1407970e831283ecb55a3
3
+ metadata.gz: 6ea7e5b91a3de304e661c781218454b4ff0236d1
4
+ data.tar.gz: 5ba67680fe3eba6feedaf932216de714e8ac9c26
5
5
  SHA512:
6
- metadata.gz: fb4be0010ee08383f2ff8ad20a329d740e08fd355b20d06a96d2b9dc273fd1b2d009dcc6a0217afe3694b158210d3d4f6310bff867e0449757d5a211a050bc85
7
- data.tar.gz: 10835489bc2d9ed4216660a8f2859aa60208b80c6162540b2de5c71acfd7b0862a1f8e90e69f3306b3888c61a81badfbdc1736b45b4667d1455666bf1e12f351
6
+ metadata.gz: 79eea88a815f4a75692009375ea89bdae49f1fb741e3af82f86c14fad188479ad2f2da1da477c715b4b7da7739613bb8209a96f33257f78db7c34d5daf1a988c
7
+ data.tar.gz: a9d97c0e7600c7d89d61e2f0ecb0133cc692f43f6fce32bad8405fa8ed1bebc36fe5687356301eef5180d9ed920dac613e11d60aa4d80fca7207885f247ca03c
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  Gemfile.lock
2
2
  coverage
3
3
  *.gem
4
+ .yardoc
5
+ doc
data/.travis.yml CHANGED
@@ -9,7 +9,7 @@ rvm:
9
9
  - ruby-2.0.0
10
10
  - ruby-2.1
11
11
  - ruby-2.2
12
- - ruby-2.3
12
+ - ruby-2.3.0
13
13
  matrix:
14
14
  fast_finish: true
15
15
  allow_failures:
data/Gemfile CHANGED
@@ -8,9 +8,22 @@ source "https://rubygems.org"
8
8
 
9
9
  gemspec
10
10
 
11
- # statistics only on MRI 2.3 - avoid problems on older rubies
12
11
  group :development do
13
- gem "redcarpet"
14
- gem "simplecov"
15
- gem "coveralls"
16
- end if RUBY_VERSION == "2.3.0"
12
+ # statistics only on MRI 2.3 - avoid problems on older rubies
13
+ if RUBY_VERSION == "2.3.0"
14
+ gem "redcarpet"
15
+ end
16
+
17
+ # lower required versions for old ruby
18
+ if RUBY_VERSION == "1.8.7"
19
+ gem "mime-types", "<2.0.0"
20
+ gem "rest-client", "<1.7.0"
21
+ #gem "listen", "<2.0.0"
22
+ end
23
+
24
+ # do not install guard in CI (save time and avoid endless gem resolution)
25
+ if ENV["CI"] != "true" && RUBY_VERSION != "1.8.7"
26
+ gem "guard", "~> 2.0"
27
+ gem "guard-minitest", "~> 2.0"
28
+ end
29
+ end
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ =begin
2
+ Copyright 2014 Michal Papis <mpapis@gmail.com>
3
+
4
+ See the file LICENSE for copying permission.
5
+ =end
6
+
7
+ default_tasks = []
8
+
9
+ begin
10
+ require "yard"
11
+ YARD::Rake::YardocTask.new do |t|
12
+ t.files = ["lib/**/*.rb"]
13
+ t.stats_options = ["--list-undoc", "--compact"]
14
+ end
15
+
16
+ task :docs => [:yard]
17
+ default_tasks << :yard
18
+ rescue LoadError
19
+ end
20
+
21
+ require "rake/testtask"
22
+ Rake::TestTask.new do |t|
23
+ t.verbose = true
24
+ t.libs.push("test")
25
+ t.pattern = "test/**/*_test.rb"
26
+ end
27
+ default_tasks << :test
28
+
29
+ task :default => default_tasks
data/lib/tree_renderer.rb CHANGED
@@ -8,21 +8,44 @@ require "date"
8
8
  require "erb"
9
9
  require "fileutils"
10
10
 
11
+ # Render a tree of files using ERB
12
+ #
13
+ # example:
14
+ #
15
+ # TreeRenderer.new("/template/path", "/target/path", variables).save
16
+ #
11
17
  class TreeRenderer
12
- attr_reader :template_path, :target_path, :var_binding
18
+ # @return [String] the path to the template directory to be rendered
19
+ attr_reader :template_path
20
+ # @return [String] the target path where to render the template
21
+ attr_reader :target_path
22
+ # @return [Binding] binding for the variables to use for rendering
23
+ attr_reader :var_binding
13
24
 
25
+ # Initialize the paths and variables for rendering
26
+ #
27
+ # @param template_path [String] the path to the template directory to be rendered
28
+ # @param target_path [String] the target path where to render the template
29
+ # @param variables [Hash, Object, Binding] the variables to use for rendering
30
+ #
14
31
  def initialize(template_path, target_path, variables = {})
15
32
  @template_path = template_path
16
33
  @target_path = target_path
17
34
  @var_binding = calculate_binding(variables)
18
35
  end
19
36
 
37
+ # Run the rendering process
20
38
  def save
21
39
  all_files.each{ |file| parse_and_save(file) }
22
40
  end
23
41
 
24
42
  private
25
43
 
44
+ # Take the initialize variables thing and transforms it to Binding
45
+ #
46
+ # @param variables [Hash, Object, Binding] the variables to use for rendering
47
+ # @return [Binding] binding for the input variables
48
+ #
26
49
  def calculate_binding(variables)
27
50
  case variables
28
51
  when Hash
@@ -35,30 +58,61 @@ private
35
58
  end
36
59
  end
37
60
 
61
+ # get list of files in the `template_path`
62
+ #
63
+ # @return [Array<String>] list of files in the `template_path` dir
64
+ #
38
65
  def all_files
39
66
  Dir.glob("#{template_path}/**/*", File::FNM_DOTMATCH).reject{|path| File.directory?(path) }.sort
40
67
  end
41
68
 
69
+ # read `file` from `template_path`, render it, amd save it in `target_path`
70
+ #
71
+ # @param file [String] path to file to render
72
+ #
42
73
  def parse_and_save(file)
43
74
  save_file(
44
75
  transform_path(file),
45
- parse_template(file),
76
+ parse_template(file)
46
77
  )
47
78
  end
48
79
 
80
+ # write `content` to the given `path`, it will create required directories
81
+ #
82
+ # @param path [String] the path of file to save to
83
+ # @param content [String] the content to save
84
+ #
49
85
  def save_file(path, content)
50
86
  FileUtils.mkdir_p(File.expand_path("..", path))
51
- File.write(path, content, 0, mode: "w")
87
+ File.open(path, "w") do |f|
88
+ f.write(content)
89
+ end
52
90
  end
53
91
 
92
+ # translates path to `file` from `template_path` to `target_path`
93
+ # it will also render it to replace file names if needed
94
+ #
95
+ # @param file [String] the file name to transform from `template_path`
96
+ # @return [String] translated file in `target_path`
97
+ #
54
98
  def transform_path(file)
55
99
  render(file.sub(template_path, target_path))
56
100
  end
57
101
 
102
+ # read and render template from `path`
103
+ #
104
+ # @param path [String] path to file to read
105
+ # @return [String] rendered content of the file
106
+ #
58
107
  def parse_template(path)
59
108
  render(File.read(path))
60
109
  end
61
110
 
111
+ # render given content
112
+ #
113
+ # @param content [String] the content to render
114
+ # @return [String] the rendered content
115
+ #
62
116
  def render(content)
63
117
  ERB.new(content).result(var_binding)
64
118
  end
@@ -1,3 +1,4 @@
1
1
  class TreeRenderer
2
- VERSION = "1.0.1"
2
+ # Version of the gem
3
+ VERSION = "1.1.0"
3
4
  end
@@ -23,7 +23,7 @@ then
23
23
  end
24
24
 
25
25
  require "minitest/autorun"
26
- require "minitest/reporters"
26
+ require "minitest/reporters" if RUBY_VERSION != "1.8.7"
27
27
  require "tmpdir"
28
28
  require "pathname"
29
29
  require "fileutils"
@@ -32,4 +32,4 @@ TREE_RENDERER_TMP_DIR = Pathname(Dir.tmpdir).join("tree_renderer")
32
32
 
33
33
  Dir['lib/**/*.rb'].each { |file| require "./#{file}" } # coverals trick for all files
34
34
 
35
- Minitest::Reporters.use!
35
+ Minitest::Reporters.use! if RUBY_VERSION != "1.8.7"
@@ -14,17 +14,17 @@ describe TreeRenderer do
14
14
 
15
15
  describe "#new" do
16
16
  it "sets binding directly" do
17
- example = OpenStruct.new(a: 1).instance_eval { binding }
17
+ example = OpenStruct.new(:a => 1).instance_eval { binding }
18
18
  subject.new("path1", "path2", example).var_binding.must_equal(example)
19
19
  end
20
20
 
21
21
  it "sets binding from object" do
22
- example = OpenStruct.new(a: 1)
22
+ example = OpenStruct.new(:a => 1)
23
23
  subject.new("path1", "path2", example).var_binding.must_be_instance_of(Binding)
24
24
  end
25
25
 
26
26
  it "sets binding from hash" do
27
- example = {a: 1}
27
+ example = {:a => 1}
28
28
  subject.new("path1", "path2", example).var_binding.must_be_instance_of(Binding)
29
29
  end
30
30
  end
@@ -34,7 +34,7 @@ describe TreeRenderer do
34
34
  FileUtils.rm_rf(TREE_RENDERER_TMP_DIR)
35
35
  end
36
36
  it "saves a file" do
37
- subject.new(File.expand_path("../../example_template", __FILE__), TREE_RENDERER_TMP_DIR.to_s, name: "example", description: "Example project template").save
37
+ subject.new(File.expand_path("../../example_template", __FILE__), TREE_RENDERER_TMP_DIR.to_s, :name => "example", :description => "Example project template").save
38
38
  Dir.chdir TREE_RENDERER_TMP_DIR do
39
39
  Dir.glob("**/*").must_equal(%w[
40
40
  README.md
@@ -83,7 +83,7 @@ CONTENT
83
83
  describe "#transform_path" do
84
84
  it "transforms paths with erb" do
85
85
  subject.new(
86
- "/path1/bin", "/path2/lib", name: "file"
86
+ "/path1/bin", "/path2/lib", :name => "file"
87
87
  ).send(
88
88
  :transform_path, "/path1/bin/some/path/<%= name %>.txt"
89
89
  ).must_equal(
@@ -95,11 +95,12 @@ CONTENT
95
95
  describe "#parse_template" do
96
96
  it "loads a file" do
97
97
  subject.new(
98
- "/path1/bin", "/path2/lib", name: "file"
98
+ "/path1/bin", "/path2/lib", :name => "file"
99
99
  ).send(
100
100
  :parse_template, File.expand_path("../../lib/tree_renderer/version.rb", __FILE__)
101
101
  ).must_equal(<<-VERSION_FILE)
102
102
  class TreeRenderer
103
+ # Version of the gem
103
104
  VERSION = "#{TreeRenderer::VERSION}"
104
105
  end
105
106
  VERSION_FILE
@@ -119,7 +120,7 @@ VERSION_FILE
119
120
 
120
121
  it "render text with erb" do
121
122
  subject.new(
122
- "/path1/bin", "/path2/lib", name: "dolor"
123
+ "/path1/bin", "/path2/lib", :name => "dolor"
123
124
  ).send(
124
125
  :render, "Lorem ipsum <%= name %>"
125
126
  ).must_equal(
@@ -10,17 +10,18 @@ Gem::Specification.new do |s|
10
10
  s.email = ["mpapis@gmail.com"]
11
11
  s.homepage = "https://github.com/mpapis/tree_renderer"
12
12
  s.summary = "Render tree of ERB templates"
13
- s.license = "Apache 2.0"
13
+ s.license = "Apache-2.0"
14
14
  s.files = `git ls-files -z`.split("\0")
15
15
  s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\0")
16
16
  s.required_ruby_version = ">= 1.9.3"
17
17
 
18
18
  s.add_development_dependency "rake", "~> 10.0"
19
- s.add_development_dependency "guard", "~> 2.0"
20
- s.add_development_dependency "guard-minitest", "~> 2.0"
21
19
  s.add_development_dependency "minitest", "~> 4.0"
22
20
  s.add_development_dependency "minitest-reporters", "~> 0"
23
- s.add_development_dependency "simplecov", "~> 0.11"
24
- s.add_development_dependency "coveralls", "~> 0.8"
21
+ if RUBY_VERSION == "2.3.0"
22
+ s.add_development_dependency "simplecov", "~> 0.11"
23
+ s.add_development_dependency "coveralls", "~> 0.8"
24
+ end
25
+ s.add_development_dependency "yard", "~> 0.8"
25
26
  # s.add_development_dependency("smf-gem")
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_renderer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Papis
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '10.0'
27
- - !ruby/object:Gem::Dependency
28
- name: guard
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: guard-minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.0'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: minitest
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -81,21 +53,7 @@ dependencies:
81
53
  - !ruby/object:Gem::Version
82
54
  version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
- name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.11'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.11'
97
- - !ruby/object:Gem::Dependency
98
- name: coveralls
56
+ name: yard
99
57
  requirement: !ruby/object:Gem::Requirement
100
58
  requirements:
101
59
  - - "~>"
@@ -120,6 +78,7 @@ files:
120
78
  - Gemfile
121
79
  - LICENSE
122
80
  - README.md
81
+ - Rakefile
123
82
  - example_template/README.md
124
83
  - example_template/lib/<%= name %>.rb
125
84
  - lib/tree_renderer.rb
@@ -129,7 +88,7 @@ files:
129
88
  - tree_renderer.gemspec
130
89
  homepage: https://github.com/mpapis/tree_renderer
131
90
  licenses:
132
- - Apache 2.0
91
+ - Apache-2.0
133
92
  metadata: {}
134
93
  post_install_message:
135
94
  rdoc_options: []
@@ -147,10 +106,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
106
  version: '0'
148
107
  requirements: []
149
108
  rubyforge_project:
150
- rubygems_version: 2.5.2
109
+ rubygems_version: 2.5.1
151
110
  signing_key:
152
111
  specification_version: 4
153
112
  summary: Render tree of ERB templates
154
113
  test_files:
155
114
  - test/minitest_helper.rb
156
115
  - test/tree_renderer_test.rb
116
+ has_rdoc: