folder_template 0.1.1 → 1.0.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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -3
  3. data/README.md +16 -3
  4. data/bin/setup_folder +5 -0
  5. data/folder_template.gemspec +5 -1
  6. data/lib/folder_template/context.rb +124 -0
  7. data/lib/folder_template/fs_adapter.rb +7 -21
  8. data/lib/folder_template/setup_folder_cmd.rb +52 -0
  9. data/lib/folder_template/template_folder.rb +25 -26
  10. data/lib/folder_template/template_folder_entry.rb +1 -1
  11. data/lib/folder_template/template_registry.rb +71 -0
  12. data/lib/folder_template/template_string.rb +4 -4
  13. data/lib/folder_template/version.rb +1 -1
  14. data/lib/folder_template.rb +8 -2
  15. data/rakefile.rb +84 -16
  16. data/templates/rubyclass/context.rb +15 -0
  17. data/{test/data/test1 → templates/rubyclass}/template/lib/>>{{project_name}}.rb +0 -0
  18. data/{test/data/test_append → templates/rubyclass}/template/lib/{{project_name}}/{{class_filename}}.rb +7 -5
  19. data/{test/data/test1/template/test_/_test_{{class_filename}}.rb → templates/rubyclass/template/test/test_{{class_filename}}.rb} +9 -6
  20. data/templates/rubygem/context.rb +15 -0
  21. data/templates/rubygem/template/Gemfile +13 -0
  22. data/templates/rubygem/template/LICENSE +22 -0
  23. data/templates/rubygem/template/README.md +49 -0
  24. data/{test/data/test1/template/lib/{{project_name}}/{{class_filename}}.rb → templates/rubygem/template/lib/{{project_name}}/version.rb} +4 -5
  25. data/templates/rubygem/template/lib/{{project_name}}.rb +12 -0
  26. data/templates/rubygem/template/rakefile.rb +110 -0
  27. data/templates/rubygem/template/test/_test_env.rb +27 -0
  28. data/{test/data/test_append/template/test_/_test_{{class_filename}}.rb → templates/rubygem/template/test/test_version.rb} +13 -10
  29. data/templates/rubygem/template/{{_}}.codeclimate.yml +25 -0
  30. data/templates/rubygem/template/{{_}}.gitignore +4 -0
  31. data/templates/rubygem/template/{{_}}.rubocop.yml +1156 -0
  32. data/templates/rubygem/template/{{_}}.travis.yml +7 -0
  33. data/templates/rubygem/template/{{project_name}}.gemspec +37 -0
  34. data/test/_test_env.rb +7 -7
  35. data/test/test_context.rb +116 -0
  36. data/test/test_fs_adapter.rb +8 -10
  37. data/test/test_setup_folder_cmd.rb +44 -0
  38. data/test/test_template_folder.rb +22 -27
  39. data/test/test_template_string.rb +24 -10
  40. data/test_data/rubygem/actual_output/Gemfile +13 -0
  41. data/test_data/rubygem/actual_output/LICENSE +22 -0
  42. data/test_data/rubygem/actual_output/README.md +108 -0
  43. data/test_data/rubygem/actual_output/_.codeclimate.yml +25 -0
  44. data/test_data/rubygem/actual_output/_.gitignore +4 -0
  45. data/test_data/rubygem/actual_output/_.rubocop.yml +1156 -0
  46. data/test_data/rubygem/actual_output/_.travis.yml +7 -0
  47. data/test_data/rubygem/actual_output/folder_name.gemspec +37 -0
  48. data/test_data/rubygem/actual_output/lib/folder_name/version.rb +12 -0
  49. data/test_data/rubygem/actual_output/lib/folder_name.rb +12 -0
  50. data/test_data/rubygem/actual_output/rakefile.rb +56 -0
  51. data/test_data/rubygem/actual_output/test/_test_env.rb +27 -0
  52. data/test_data/rubygem/actual_output/test/test_version.rb +23 -0
  53. data/test_data/rubygem/expected_output/Gemfile +13 -0
  54. data/test_data/rubygem/expected_output/LICENSE +22 -0
  55. data/test_data/rubygem/expected_output/README.md +108 -0
  56. data/test_data/rubygem/expected_output/_.codeclimate.yml +25 -0
  57. data/test_data/rubygem/expected_output/_.gitignore +4 -0
  58. data/test_data/rubygem/expected_output/_.rubocop.yml +1156 -0
  59. data/test_data/rubygem/expected_output/_.travis.yml +7 -0
  60. data/test_data/rubygem/expected_output/folder_name.gemspec +37 -0
  61. data/test_data/rubygem/expected_output/lib/folder_name/version.rb +12 -0
  62. data/test_data/rubygem/expected_output/lib/folder_name.rb +12 -0
  63. data/test_data/rubygem/expected_output/rakefile.rb +56 -0
  64. data/test_data/rubygem/expected_output/test/_test_env.rb +27 -0
  65. data/test_data/rubygem/expected_output/test/test_version.rb +23 -0
  66. data/test_data/rubygem/template_definition/context.rb +13 -0
  67. data/test_data/rubygem/template_definition/template/Gemfile +13 -0
  68. data/test_data/rubygem/template_definition/template/LICENSE +22 -0
  69. data/test_data/rubygem/template_definition/template/README.md +108 -0
  70. data/test_data/rubygem/template_definition/template/lib/{{project_name}}/version.rb +12 -0
  71. data/test_data/rubygem/template_definition/template/lib/{{project_name}}.rb +12 -0
  72. data/test_data/rubygem/template_definition/template/rakefile.rb +56 -0
  73. data/test_data/rubygem/template_definition/template/test/_test_env.rb +27 -0
  74. data/test_data/rubygem/template_definition/template/test/test_version.rb +23 -0
  75. data/test_data/rubygem/template_definition/template/{{_}}.codeclimate.yml +25 -0
  76. data/test_data/rubygem/template_definition/template/{{_}}.gitignore +4 -0
  77. data/test_data/rubygem/template_definition/template/{{_}}.rubocop.yml +1156 -0
  78. data/test_data/rubygem/template_definition/template/{{_}}.travis.yml +7 -0
  79. data/test_data/rubygem/template_definition/template/{{project_name}}.gemspec +37 -0
  80. metadata +112 -55
  81. data/test/data/test1/actual_output/lib/project_aaa/cls_fn.rb +0 -13
  82. data/test/data/test1/actual_output/lib/project_aaa.rb +0 -1
  83. data/test/data/test1/actual_output/test_/_test_cls_fn.rb +0 -20
  84. data/test/data/test1/expected_output/lib/project_aaa/cls_fn.rb +0 -13
  85. data/test/data/test1/expected_output/lib/project_aaa.rb +0 -1
  86. data/test/data/test1/expected_output/test_/_test_cls_fn.rb +0 -20
  87. data/test/data/test_append/actual_output/lib/project_aaa/cls1_fn.rb +0 -13
  88. data/test/data/test_append/actual_output/lib/project_aaa/cls2_fn.rb +0 -13
  89. data/test/data/test_append/actual_output/lib/project_aaa/cls3_fn.rb +0 -13
  90. data/test/data/test_append/actual_output/lib/project_aaa.rb +0 -3
  91. data/test/data/test_append/actual_output/test_/_test_cls1_fn.rb +0 -20
  92. data/test/data/test_append/actual_output/test_/_test_cls2_fn.rb +0 -20
  93. data/test/data/test_append/actual_output/test_/_test_cls3_fn.rb +0 -20
  94. data/test/data/test_append/expected_output/lib/project_aaa/cls1_fn.rb +0 -13
  95. data/test/data/test_append/expected_output/lib/project_aaa/cls2_fn.rb +0 -13
  96. data/test/data/test_append/expected_output/lib/project_aaa/cls3_fn.rb +0 -13
  97. data/test/data/test_append/expected_output/lib/project_aaa.rb +0 -3
  98. data/test/data/test_append/expected_output/test_/_test_cls1_fn.rb +0 -20
  99. data/test/data/test_append/expected_output/test_/_test_cls2_fn.rb +0 -20
  100. data/test/data/test_append/expected_output/test_/_test_cls3_fn.rb +0 -20
  101. data/test/data/test_append/template/lib/>>{{project_name}}.rb +0 -1
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ # - jruby
7
+ # - rbx-2
@@ -0,0 +1,37 @@
1
+ # =============================================================================
2
+ #
3
+ # MODULE : {{filename}}
4
+ # PROJECT : {{project_namespace}}
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) {{copyright_year}}, {{copyright_owner}}. All rights reserved.
8
+ # =============================================================================
9
+
10
+
11
+ require_relative 'lib/{{project_name}}/version.rb'
12
+
13
+ Gem::Specification.new do |spec|
14
+ spec.name = '{{project_name}}'
15
+ spec.version = {{project_namespace}}::VERSION
16
+ spec.authors = ["{{copyright_owner}}"]
17
+ spec.email = [""]
18
+ spec.summary = ""
19
+ spec.description = %q{
20
+ }.gsub( /\s+/, ' ').strip
21
+ spec.homepage = ""
22
+
23
+ spec.files = Dir['[A-Z]*', 'rakefile.rb', '*.gemspec'].reject { |f| f =~ /.lock/ }
24
+ spec.files += Dir['bin/**', 'lib/**/*.rb', 'test/**/*.rb', 'spec/**/*.rb', 'features/**/*.rb']
25
+ spec.executables = spec.files.grep( %r{^bin/} ) { |f| File.basename(f) }
26
+ spec.test_files = spec.files.grep( %r{^(test|spec|features)/} )
27
+
28
+ # spec.add_runtime_dependency 'facets', '~> 3.0'
29
+ # spec.add_runtime_dependency 'mustache', '~> 1.0'
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.7'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'watch', '~> 0.1'
34
+ spec.add_development_dependency 'rr', '~> 1.1'
35
+ spec.add_development_dependency 'minitest', '~> 5.3'
36
+ spec.add_development_dependency 'minitest-reporters', '~> 1.1'
37
+ end
data/test/_test_env.rb CHANGED
@@ -1,31 +1,31 @@
1
1
  # =============================================================================
2
- #
2
+ #
3
3
  # MODULE : test/_test_env.rb
4
4
  # PROJECT : RubyProjectGenerator
5
- # DESCRIPTION :
5
+ # DESCRIPTION :
6
6
  #
7
7
  # Copyright (c) 2016, Marc-Antoine Argenton. All rights reserved.
8
8
  # =============================================================================
9
9
 
10
10
  require 'minitest/autorun'
11
+ require 'minitest/reporters'
11
12
  require 'fileutils'
12
13
  require 'pp'
13
14
  require 'rr'
14
15
 
15
16
  require 'lib/folder_template.rb'
16
17
 
18
+ # Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
17
19
 
18
20
 
19
21
  module Minitest::Assertions
20
22
  def assert_folders_match( expected_folder, actual_folder )
21
23
  diffs = _diff_folders( expected_folder, actual_folder )
22
- assert diffs.empty?,
23
- "Expected folders content to match:\n#{diffs}\n"
24
- # "Expected folders to match:\nexpected: #{expected_folder.inspect}\nactual: #{expected_folder.inspect}\ndiffs:\n#{diffs}"
24
+ assert diffs.empty?, "Expected folders content to match:\n#{diffs}\n"
25
25
  end
26
-
26
+
27
27
  private
28
28
  def _diff_folders( expected_folder, actual_folder )
29
29
  `diff -r -u --exclude=.DS_Store #{expected_folder} #{actual_folder}`
30
30
  end
31
- end
31
+ end
@@ -0,0 +1,116 @@
1
+
2
+ # =============================================================================
3
+ #
4
+ # MODULE : test/ruby_project_generator/template_string.rb
5
+ # PROJECT : RubyProjectGenerator
6
+ # DESCRIPTION :
7
+ #
8
+ # Copyright (c) 2016, Marc-Antoine Argenton. All rights reserved.
9
+ # =============================================================================
10
+
11
+
12
+ require '_test_env.rb'
13
+
14
+
15
+ module FolderTemplate
16
+ describe Context do
17
+
18
+ describe "it implements DSL to support value lazzy definition" do
19
+ let( :filename ) { 'path/to/context_file' }
20
+ let( :content ) { "let( :bbb ) { aaa + 1 if aaa }" }
21
+ subject { Context.load_from_content( content, filename ) }
22
+
23
+ it "holds definition for values declared in context DSL file" do
24
+ subject.merge!( aaa:123 )
25
+ subject[:bbb].must_equal( 124 )
26
+ end
27
+ end
28
+
29
+
30
+ describe "it behaves like a Hash" do
31
+ subject {
32
+ ctx = Context.new
33
+ ctx.let( :bbb ) { aaa + 1 }
34
+ ctx.let( :aaa ) { 123 }
35
+ ctx
36
+ }
37
+
38
+ it "supports value accessor with symbols" do
39
+ subject[:bbb].must_equal( 124 )
40
+ end
41
+
42
+ it "supports value assignment with symbols" do
43
+ subject[:aaa] = 112
44
+ subject[:aaa].must_equal( 112 )
45
+ end
46
+
47
+ it "updates evaluation of dependent variables after value assignment" do
48
+ subject[:aaa] = 112
49
+ subject[:bbb].must_equal( 113 )
50
+ end
51
+
52
+ it "responds to values like a Hash" do
53
+ Set.new(subject.values).must_equal( Set.new([123, 124]) )
54
+ end
55
+
56
+ it "responds to each like a Hash" do
57
+ kv_pairs = subject.each.to_a
58
+ kv_pairs.must_equal( [[:bbb, 124], [:aaa, 123]] )
59
+ end
60
+ end # it behaves like a Hash
61
+
62
+
63
+ describe "it can be copies with all definies variables" do
64
+ subject {
65
+ ctx = Context.new
66
+ ctx.let( :ccc ) { aaa + bbb }
67
+ ctx.let( :aaa ) { 123 }
68
+ ctx
69
+ }
70
+
71
+ it "creates an independant contexts for each copy" do
72
+ ctx1 = subject.dup
73
+ ctx2 = subject.dup
74
+ ctx1[:bbb] = 1
75
+ ctx2[:bbb] = 2
76
+ ctx1[:ccc].must_equal( 124 )
77
+ ctx2[:ccc].must_equal( 125 )
78
+ end
79
+
80
+ it "merge() creates a duplicated instance of the conext" do
81
+ ctx1 = subject.merge( bbb:1 )
82
+ ctx2 = subject.merge( bbb:2 )
83
+ ctx1[:ccc].must_equal( 124 )
84
+ ctx2[:ccc].must_equal( 125 )
85
+ end
86
+ end
87
+
88
+
89
+ describe "it caches pre-evaluated values" do
90
+ subject { Context.new }
91
+
92
+ it "evaluates values only once" do
93
+ subject.let( :aaa ) { 123 }
94
+ subject.aaa.must_equal( 123 )
95
+ subject.definitions.delete( :aaa )
96
+ subject.aaa.must_equal( 123 )
97
+ end
98
+
99
+ it "clears cached values when variables are re-declared" do
100
+ subject.let( :aaa ) { 123 }
101
+ subject.aaa.must_equal( 123 )
102
+ subject.let( :aaa ) { 124 }
103
+ subject.aaa.must_equal( 124 )
104
+ end
105
+
106
+ it "re-evalutes dependant values after a change of definition" do
107
+ subject.let( :aaa ) { 123 }
108
+ subject.let( :bbb ) { aaa + 1 }
109
+ subject.bbb.must_equal( 124 )
110
+ subject.let( :aaa ) { 124 }
111
+ subject.bbb.must_equal( 125 )
112
+ end
113
+ end
114
+
115
+ end # describe Context
116
+ end
@@ -1,8 +1,8 @@
1
1
  # =============================================================================
2
- #
2
+ #
3
3
  # MODULE : lib/ruby_project_generator/test_fs_adapter.rb
4
4
  # PROJECT : RubyProjectGenerator
5
- # DESCRIPTION :
5
+ # DESCRIPTION :
6
6
  #
7
7
  # Copyright (c) 2016, Marc-Antoine Argenton. All rights reserved.
8
8
  # =============================================================================
@@ -16,41 +16,39 @@ module FolderTemplate
16
16
  describe FsAdapter do
17
17
  let( :tmpdir ) { "tmp" }
18
18
  subject { FsAdapter.new( tmpdir ) }
19
-
19
+
20
20
  before do
21
21
  stub(FileUtils).makedirs()
22
22
  stub(File).open()
23
23
  stub(File).write()
24
24
  end
25
-
25
+
26
26
  describe "when calling makedirs()" do
27
27
  it "expands filename and calls FileUtils.makedirs()" do
28
28
  mock(FileUtils).makedirs( File.join( tmpdir, "aaa/bbb" ) )
29
29
  subject.makedirs( "aaa/bbb" )
30
30
  end
31
31
  end
32
-
32
+
33
33
  describe "when calling write_to_file()" do
34
34
  it "expands filename, creates containing folder and calls File.write()" do
35
35
  expected_filename = File.join( tmpdir, "aaa/bbb" )
36
36
  mock(FileUtils).makedirs( File.dirname( expected_filename ) )
37
37
  mock(File).write( expected_filename, "bbb" )
38
-
38
+
39
39
  subject.write_to_file( "aaa/bbb", "bbb" )
40
40
  end
41
41
  end
42
-
42
+
43
43
  describe "when calling append_to_file()" do
44
44
  it "expands filename, opens file for append and appends content" do
45
45
  expected_filename = File.join( tmpdir, "aaa/bbb" )
46
46
  mock(FileUtils).makedirs( File.dirname( expected_filename ) )
47
47
  mock(File).open( expected_filename, "a" )
48
-
48
+
49
49
  subject.append_to_file( "aaa/bbb", "bbb" )
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
54
  end
55
-
56
-
@@ -0,0 +1,44 @@
1
+ # =============================================================================
2
+ #
3
+ # MODULE : lib/ruby_project_generator/test_setup_folder_cmd.rb
4
+ # PROJECT : RubyProjectGenerator
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) 2016, Marc-Antoine Argenton. All rights reserved.
8
+ # =============================================================================
9
+
10
+
11
+ require '_test_env.rb'
12
+
13
+
14
+ module FolderTemplate
15
+ describe SetupFolderCmd do
16
+
17
+ it "requires a least two command line arguments" do
18
+ err = assert_raises RuntimeError do
19
+ SetupFolderCmd.new()
20
+ end
21
+ err.message.must_match /missing/i
22
+ err.message.must_match /required/i
23
+ err.message.must_match /arguments/i
24
+ end
25
+
26
+ it "extracts target_path and template_name from argument list" do
27
+ cmd = SetupFolderCmd.new( '.', 'rubygem' )
28
+ cmd.target_path.must_equal( File.expand_path( '.' ) )
29
+ cmd.template_name.must_equal( 'rubygem' )
30
+ end
31
+
32
+ it "parses variables definition" do
33
+ cmd = SetupFolderCmd.new( '.', 'rubygem', 'aaa=123', 'bbb=234' )
34
+ cmd.variables.must_equal( { aaa:'123', bbb:'234' } )
35
+ end
36
+
37
+ it "locates the template directory based on the requested name" do
38
+ cmd = SetupFolderCmd.new( '.', 'rubygem', 'aaa=123', 'bbb=234' )
39
+ cmd.template_path.wont_be_nil
40
+ TemplateFolder.validate_template_path( cmd.template_path ).must_equal true
41
+ end
42
+
43
+ end # describe SetupFolderCmd
44
+ end # module FolderTemplate
@@ -1,8 +1,8 @@
1
1
  # =============================================================================
2
- #
2
+ #
3
3
  # MODULE : lib/ruby_project_generator/version.rb
4
4
  # PROJECT : RubyProjectGenerator
5
- # DESCRIPTION :
5
+ # DESCRIPTION :
6
6
  #
7
7
  # Copyright (c) 2016, Marc-Antoine Argenton. All rights reserved.
8
8
  # =============================================================================
@@ -14,23 +14,20 @@ require '_test_env.rb'
14
14
  module FolderTemplate
15
15
 
16
16
  describe TemplateFolder do
17
- let( :data_base_path ) { File.join( FolderTemplate::BASE_PATH, 'test', 'data' ) }
18
- let( :template ) { TemplateFolder.new( File.join( data_base_path, data_test_name, 'template' ) ) }
17
+ let( :data_base_path ) { File.join( FolderTemplate::BASE_PATH, 'test_data' ) }
18
+ let( :template ) { TemplateFolder.new( File.join( data_base_path, data_test_name, 'template_definition' ) ) }
19
19
  let( :expected_output_path ) { File.join( data_base_path, data_test_name, 'expected_output' ) }
20
20
  let( :actual_output_path ) { File.join( data_base_path, data_test_name, 'actual_output' ) }
21
- let( :base_env ) { Hash.new.merge( project_name: 'project_aaa',
22
- project_namespace: 'ProjectAaa',
23
- copyright_owner: 'Me',
24
- copyright_year: 'YEAR' ) }
25
21
 
26
22
  before do
27
23
  FileUtils.rm_rf( actual_output_path )
28
24
  FileUtils.makedirs( actual_output_path )
29
25
  end
30
-
31
- describe "test1" do
32
- let( :data_test_name ) { 'test1' }
33
- let( :env ) { base_env.merge( class_filename:'cls_fn', class_name:'ClsName' ) }
26
+
27
+
28
+ describe "rubygem" do
29
+ let( :data_test_name ) { 'rubygem' }
30
+ let( :env ) { {}.merge( folder_name:'folder_name' ) }
34
31
 
35
32
  it "" do
36
33
  fs = FsAdapter.new( actual_output_path, verbose:false )
@@ -40,23 +37,21 @@ module FolderTemplate
40
37
  end
41
38
  end
42
39
 
43
- describe "test_append" do
44
- let( :data_test_name ) { 'test_append' }
45
- let( :env ) { base_env }
46
-
47
- it "" do
48
- fs = FsAdapter.new( actual_output_path, verbose:false )
49
- template.generate( fs, env.merge( class_filename:'cls1_fn', class_name:'Cls1Name') )
50
- template.generate( fs, env.merge( class_filename:'cls2_fn', class_name:'Cls2Name') )
51
- template.generate( fs, env.merge( class_filename:'cls3_fn', class_name:'Cls3Name') )
52
-
53
- assert_folders_match( expected_output_path, actual_output_path )
54
- end
55
- end
40
+ # describe "test_append" do
41
+ # let( :data_test_name ) { 'test_append' }
42
+ # let( :env ) { base_env }
43
+ #
44
+ # it "" do
45
+ # fs = FsAdapter.new( actual_output_path, verbose:false )
46
+ # template.generate( fs, env.merge( class_filename:'cls1_fn', class_name:'Cls1Name') )
47
+ # template.generate( fs, env.merge( class_filename:'cls2_fn', class_name:'Cls2Name') )
48
+ # template.generate( fs, env.merge( class_filename:'cls3_fn', class_name:'Cls3Name') )
49
+ #
50
+ # assert_folders_match( expected_output_path, actual_output_path )
51
+ # end
52
+ # end
56
53
 
57
54
 
58
55
  end # describe TemplateFolder
59
56
 
60
57
  end
61
-
62
-
@@ -1,8 +1,8 @@
1
1
  # =============================================================================
2
- #
2
+ #
3
3
  # MODULE : test/ruby_project_generator/template_string.rb
4
4
  # PROJECT : RubyProjectGenerator
5
- # DESCRIPTION :
5
+ # DESCRIPTION :
6
6
  #
7
7
  # Copyright (c) 2016, Marc-Antoine Argenton. All rights reserved.
8
8
  # =============================================================================
@@ -13,11 +13,11 @@ require '_test_env.rb'
13
13
 
14
14
  module FolderTemplate
15
15
  describe TemplateString do
16
-
16
+
17
17
  describe "when initialized with a string" do
18
18
  let(:template_string) { "prefix {{arg1}} infix {{arg2}} suffix" }
19
19
  subject { TemplateString.new( template_string )}
20
-
20
+
21
21
  it "parses template string into an Array" do
22
22
  subject.content.must_be_kind_of Array
23
23
  end
@@ -34,12 +34,12 @@ module FolderTemplate
34
34
  it "extracts variables from definition string" do
35
35
  subject.variables.must_equal Set.new( [:arg1, :arg2] )
36
36
  end
37
-
37
+
38
38
  it "evaluates to original template string" do
39
39
  "#{subject}".must_equal template_string
40
40
  end
41
41
  end
42
-
42
+
43
43
 
44
44
  describe "when initialized special string" do
45
45
  it "finds all variables" do
@@ -52,12 +52,13 @@ module FolderTemplate
52
52
  strings = template.content.select{ |s| String === s }
53
53
  strings.must_equal( [" prefix ", " suffix "])
54
54
  end
55
+
55
56
  end
56
57
 
57
58
  describe "calling expand" do
58
59
  let(:template_string) { "prefix {{arg1}} infix {{arg2}} suffix" }
59
60
  subject { TemplateString.new( template_string )}
60
-
61
+
61
62
  it "expands variables using environment" do
62
63
  "#{subject.expand( arg1:"aaa", arg2:"bbb")}".must_equal "prefix aaa infix bbb suffix"
63
64
  end
@@ -86,9 +87,22 @@ module FolderTemplate
86
87
  end
87
88
  "#{result}".must_equal "prefix aaa infix suffix"
88
89
  end
90
+
89
91
  end
90
-
91
- end # describe TemplateString
92
- end
93
92
 
93
+ describe "when using bare undersore variable" do
94
+ let(:template_string) { "{{_}}.gitignore" }
95
+ subject { TemplateString.new( template_string )}
94
96
 
97
+ it "accepts bare underscore variable" do
98
+ subject.variables.must_equal Set.new( [:_] )
99
+ end
100
+
101
+ it "can expand bare underscore to nothing" do
102
+ result = subject.expand( _: "" )
103
+ "#{result}".must_equal ".gitignore"
104
+ end
105
+ end
106
+
107
+ end # describe TemplateString
108
+ end
@@ -0,0 +1,13 @@
1
+ # =============================================================================
2
+ #
3
+ # MODULE : Gemfile
4
+ # PROJECT : FolderName
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) <<test_year>>, <<test_user>>. All rights reserved.
8
+ # =============================================================================
9
+
10
+
11
+
12
+ source 'https://rubygems.org'
13
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) <<test_year>>, <<test_user>>. All rights reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,108 @@
1
+ # FolderTemplate
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/folder_template.svg)](https://badge.fury.io/rb/folder_template)
4
+ [![Build Status](https://travis-ci.org/marcus999/folder_template.svg?branch=master)](https://travis-ci.org/marcus999/folder_template)
5
+ [![Code Climate](https://codeclimate.com/github/Marcus999/folder_template/badges/gpa.svg)](https://codeclimate.com/github/Marcus999/folder_template)
6
+ [![Issue Count](https://codeclimate.com/github/Marcus999/folder_template/badges/issue_count.svg)](https://codeclimate.com/github/Marcus999/folder_template)
7
+
8
+
9
+
10
+
11
+ FolderTemplate is a minimalistic template engine that generates files and
12
+ folders structure from a template folder layout. It includes a simple variable
13
+ expansion syntax, automatically injects variables for filename and basename,
14
+ and can optionally append content to existing files.
15
+
16
+
17
+ ## Template definitions
18
+
19
+ - Templates are defined as files and folders on disk
20
+ - Variables are surrounded with double curly: `{{variable}}`
21
+ - Variables can be part of filenames, folder names, and file content
22
+ - Template filename with a `>>` prefix will append their content to an existing file
23
+
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require 'folder_template'
29
+
30
+ template = FolderTemplate::TemplateFolder.new( template_path )
31
+ fs = FolderTemplate::FsAdapter.new( output_path, opts... )
32
+ env = Hash.new.merge( project_name:"my_project", ... )
33
+
34
+ template.generate( fs, env )
35
+ ```
36
+
37
+
38
+ ## FsAdapter
39
+
40
+ All filesystem operation are abstracted through an `FsAdapter` object that
41
+ performs final filename expansion, and execute all filesystem manipulations.
42
+
43
+ The `FsAdapter` interface is composed of 3 methods; any class implementing
44
+ those 3 methods can be used in place of the default `FsAdapter` object to
45
+ perform the necessary filesystem operations.
46
+
47
+ ```ruby
48
+ def makedirs( dirname )
49
+ def write_to_file( filename, content )
50
+ def append_to_file( filename, content )
51
+ ```
52
+
53
+ Default implementation of `FsAdapter` accepts a few options:
54
+
55
+ | Option | Default | Description |
56
+ | ------------------ |---------|-----------------------|
57
+ | `verbose` | `false` | When `true`, log each operation that is performed |
58
+ | `overwrite_files` | `false` | When `true`, replace existing files with content generated from template |
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+ # Project
71
+
72
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/__project__`. To experiment with that code, run `bin/console` for an interactive prompt.
73
+
74
+ TODO: Delete this and the text above, and describe your gem
75
+
76
+ ## Installation
77
+
78
+ Add this line to your application's Gemfile:
79
+
80
+ ```ruby
81
+ gem '__project__'
82
+ ```
83
+
84
+ And then execute:
85
+
86
+ $ bundle
87
+
88
+ Or install it yourself as:
89
+
90
+ $ gem install __project__
91
+
92
+ ## Usage
93
+
94
+ TODO: Write usage instructions here
95
+
96
+ ## Development
97
+
98
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
99
+
100
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
101
+
102
+ ## Contributing
103
+
104
+ 1. Fork it ( https://github.com/[my-github-username]/__project__/fork )
105
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
106
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
107
+ 4. Push to the branch (`git push origin my-new-feature`)
108
+ 5. Create a new Pull Request
@@ -0,0 +1,25 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ - javascript
9
+ - python
10
+ - php
11
+ fixme:
12
+ enabled: true
13
+ rubocop:
14
+ enabled: true
15
+ ratings:
16
+ paths:
17
+ - "**.inc"
18
+ - "**.js"
19
+ - "**.jsx"
20
+ - "**.module"
21
+ - "**.php"
22
+ - "**.py"
23
+ - "**.rb"
24
+ exclude_paths:
25
+ - test/
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /pkg/
4
+ /tmp/