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,15 @@
1
+ # rubygem/context.rb
2
+
3
+ # Required variables:
4
+ # - name : The name of the class to be created
5
+
6
+ # Variables inherited from project context
7
+ # - project_name
8
+ # - project_namespace
9
+ # - copyright_owner
10
+ # - copyright_year
11
+
12
+
13
+ let( :class_filename ) { name.underscore }
14
+ let( :class_name ) { class_filename.capitalize.camelcase }
15
+ let( :_ ) { '' }
@@ -1,13 +1,15 @@
1
1
  # =============================================================================
2
- #
3
- # MODULE : lib/{{project_name}}/{{class_filename}}.rb
2
+ #
3
+ # MODULE : {{filename}}
4
4
  # PROJECT : {{project_namespace}}
5
- # DESCRIPTION :
5
+ # DESCRIPTION :
6
6
  #
7
7
  # Copyright (c) {{copyright_year}}, {{copyright_owner}}. All rights reserved.
8
8
  # =============================================================================
9
9
 
10
10
  module {{project_namespace}}
11
11
  class {{class_name}}
12
- end
13
- end
12
+
13
+
14
+ end # class {{class_name}}
15
+ end # module {{project_namespace}}
@@ -1,20 +1,23 @@
1
1
  # =============================================================================
2
- #
3
- # MODULE : test/{{project_name}}/test_{{class_filename}}.rb
2
+ #
3
+ # MODULE : {{filename}}
4
4
  # PROJECT : {{project_namespace}}
5
- # DESCRIPTION :
5
+ # DESCRIPTION :
6
6
  #
7
7
  # Copyright (c) {{copyright_year}}, {{copyright_owner}}. All rights reserved.
8
8
  # =============================================================================
9
9
 
10
+
11
+ require '_test_env.rb'
12
+
10
13
  module {{project_namespace}}
11
-
12
14
  describe {{class_name}} do
15
+
13
16
  subject { {{class_name}}.new }
14
-
17
+
15
18
  it "passes this one" do
16
19
  subject.must_be_instance_of {{class_name}}
17
20
  end
18
- end
19
21
 
22
+ end
20
23
  end
@@ -0,0 +1,15 @@
1
+ # rubygem/context.rb
2
+
3
+ # Required variables:
4
+ # - target_path : path in which the template will be expanded
5
+
6
+
7
+ let( :folder_name ) { File.basename(target_path) }
8
+
9
+ let( :project_name ) { folder_name }
10
+ let( :project_namespace ) { folder_name.capitalize.camelcase }
11
+ let( :username ) { `id -F`.strip }
12
+ let( :copyright_owner ) { username }
13
+ let( :copyright_year ) { Time.now.year }
14
+
15
+ let( :_ ) { '' }
@@ -0,0 +1,13 @@
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
+
12
+ source 'https://rubygems.org'
13
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) {{copyright_year}}, {{copyright_owner}}. 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,49 @@
1
+ # FolderTemplate
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/{{project_name}}.svg)](https://badge.fury.io/rb/{{project_name}})
4
+ [![Build Status](https://travis-ci.org/{{travis_account}}/{{project_name}}.svg?branch=master)](https://travis-ci.org/{{travis_account}}/{{project_name}})
5
+ [![Code Climate](https://codeclimate.com/github/{{github_account}}/{{project_name}}/badges/gpa.svg)](https://codeclimate.com/github/{{github_account}}/{{project_name}})
6
+ [![Issue Count](https://codeclimate.com/github/{{github_account}}/{{project_name}}/badges/issue_count.svg)](https://codeclimate.com/github/{{github_account}}/{{project_name}})
7
+
8
+
9
+
10
+
11
+ # Project
12
+
13
+ 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_name}}`. To experiment with that code, run `bin/console` for an interactive prompt.
14
+
15
+ TODO: Delete this and the text above, and describe your gem
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem '{{project_name}}'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install {{project_name}}
32
+
33
+ ## Usage
34
+
35
+ TODO: Write usage instructions here
36
+
37
+ ## Development
38
+
39
+ 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.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/[my-github-username]/{{project_name}}/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
@@ -1,13 +1,12 @@
1
1
  # =============================================================================
2
- #
3
- # MODULE : lib/{{project_name}}/{{class_filename}}.rb
2
+ #
3
+ # MODULE : {{filename}}
4
4
  # PROJECT : {{project_namespace}}
5
- # DESCRIPTION :
5
+ # DESCRIPTION :
6
6
  #
7
7
  # Copyright (c) {{copyright_year}}, {{copyright_owner}}. All rights reserved.
8
8
  # =============================================================================
9
9
 
10
10
  module {{project_namespace}}
11
- class {{class_name}}
12
- end
11
+ VERSION = '0.0.1'
13
12
  end
@@ -0,0 +1,12 @@
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
+
12
+ require_relative '{{project_name}}/version.rb'
@@ -0,0 +1,110 @@
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 'bundler/gem_tasks'
12
+ require 'rake/testtask'
13
+
14
+ task default: [:test, :build]
15
+
16
+ Rake::TestTask.new do |t|
17
+ t.libs << '.' << 'test'
18
+ t.test_files = FileList['test/**/test_*.rb']
19
+ t.verbose = false
20
+ end
21
+
22
+
23
+
24
+ # ----------------------------------------------------------------------------
25
+ # Definitions to help formating 'rake watch' results
26
+ # ----------------------------------------------------------------------------
27
+
28
+ TERM_WIDTH = `tput cols`.to_i || 80
29
+
30
+ def tty_red(str); "\e[31m#{str}\e[0m" end
31
+ def tty_green(str); "\e[32m#{str}\e[0m" end
32
+ def tty_blink(str); "\e[5m#{str}\e[25m" end
33
+ def tty_reverse_color(str); "\e[7m#{str}\e[27m" end
34
+
35
+ def print_separator( success = true )
36
+ if success
37
+ puts tty_green( "-" * TERM_WIDTH )
38
+ else
39
+ puts tty_reverse_color(tty_red( "-" * TERM_WIDTH ))
40
+ end
41
+ end
42
+
43
+
44
+
45
+ # ----------------------------------------------------------------------------
46
+ # Definition of watch task, that monitors the project folder for any relevant
47
+ # file change and runs the unit test of the project.
48
+ # ----------------------------------------------------------------------------
49
+
50
+ begin
51
+ require 'watch'
52
+
53
+ desc 'Run unit tests everytime a source or test file is changed'
54
+ task :watch do
55
+ Watch.new( '**/*.rb' ) do
56
+ success = system "clear && rake test"
57
+ print_separator( success )
58
+ end
59
+ end
60
+
61
+ rescue LoadError
62
+
63
+ desc 'Run unit tests everytime a source or test file is changed'
64
+ task :watch do
65
+ puts
66
+ puts "'rake watch' requires the watch gem to be available"
67
+ puts
68
+ puts "To install:"
69
+ puts " gem install watch"
70
+ puts " or "
71
+ puts " sudo gem install watch"
72
+ puts
73
+ fail
74
+ end
75
+ end
76
+
77
+
78
+
79
+ # ----------------------------------------------------------------------------
80
+ # Definition of add_class[class_name] task, that uses folder_template to add
81
+ # a new class to a ruvy project
82
+ # ----------------------------------------------------------------------------
83
+
84
+ PROJECT_CONTEXT = {
85
+ project_name: "{{project_name}}",
86
+ project_namespace: "{{project_namespace}}",
87
+ copyright_owner: "{{copyright_owner}}",
88
+ copyright_year: "{{copyright_year}}",
89
+ }
90
+
91
+ begin
92
+ require 'folder_template'
93
+
94
+ task :add_class, :class_name do |t, args|
95
+ context = PROJECT_CONTEXT.merge( name:args[:class_name])
96
+ FolderTemplate::SetupFolderCmd.run( '.', 'rubyclass', context )
97
+ end
98
+ rescue LoadError
99
+ task :add_class, :class_name do |t, args|
100
+ puts
101
+ puts "'rake add_class[class_name]' task requires the folder_template gem to be available"
102
+ puts
103
+ puts "To install:"
104
+ puts " gem install folder_template"
105
+ puts " or "
106
+ puts " sudo gem install folder_template"
107
+ puts
108
+ fail
109
+ end
110
+ end
@@ -0,0 +1,27 @@
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
+ require 'minitest/autorun'
11
+ require 'minitest/reporters'
12
+ require 'fileutils'
13
+ require 'pp'
14
+ require 'rr'
15
+
16
+ require 'lib/{{project_name}}.rb'
17
+
18
+ # Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
19
+
20
+
21
+ module Minitest::Assertions
22
+ def assert_custom( expected, actual )
23
+ assert false, "assert_custom() always fails\n" +
24
+ " Expected: #{expected.inspect}\n" +
25
+ " Actak: #{actual.inspect}\n"
26
+ end
27
+ end
@@ -1,20 +1,23 @@
1
1
  # =============================================================================
2
- #
3
- # MODULE : test/{{project_name}}/test_{{class_filename}}.rb
2
+ #
3
+ # MODULE : {{filename}}
4
4
  # PROJECT : {{project_namespace}}
5
- # DESCRIPTION :
5
+ # DESCRIPTION :
6
6
  #
7
7
  # Copyright (c) {{copyright_year}}, {{copyright_owner}}. All rights reserved.
8
8
  # =============================================================================
9
9
 
10
+
11
+ require '_test_env.rb'
12
+
10
13
  module {{project_namespace}}
11
-
12
- describe {{class_name}} do
13
- subject { {{class_name}}.new }
14
-
15
- it "passes this one" do
16
- subject.must_be_instance_of {{class_name}}
14
+ describe VERSION do
15
+
16
+ subject { VERSION }
17
+
18
+ it "is definied as a string" do
19
+ subject.must_be_instance_of String
17
20
  end
18
- end
19
21
 
22
+ end
20
23
  end
@@ -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/