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 : folder_name.gemspec
4
+ # PROJECT : FolderName
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) <<test_year>>, <<test_user>>. All rights reserved.
8
+ # =============================================================================
9
+
10
+
11
+ require_relative 'lib/folder_name/version.rb'
12
+
13
+ Gem::Specification.new do |spec|
14
+ spec.name = 'folder_name'
15
+ spec.version = FolderName::VERSION
16
+ spec.authors = ["<<test_user>>"]
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
@@ -0,0 +1,12 @@
1
+ # =============================================================================
2
+ #
3
+ # MODULE : lib/folder_name/version.rb
4
+ # PROJECT : FolderName
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) <<test_year>>, <<test_user>>. All rights reserved.
8
+ # =============================================================================
9
+
10
+ module FolderName
11
+ VERSION = '0.0.1'
12
+ end
@@ -0,0 +1,12 @@
1
+ # =============================================================================
2
+ #
3
+ # MODULE : lib/folder_name.rb
4
+ # PROJECT : FolderName
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) <<test_year>>, <<test_user>>. All rights reserved.
8
+ # =============================================================================
9
+
10
+
11
+
12
+ require_relative 'folder_name/version.rb'
@@ -0,0 +1,56 @@
1
+ # =============================================================================
2
+ #
3
+ # MODULE : rakefile.rb
4
+ # PROJECT : FolderName
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) <<test_year>>, <<test_user>>. All rights reserved.
8
+ # =============================================================================
9
+
10
+
11
+ require 'bundler/gem_tasks'
12
+ require 'rake/testtask'
13
+
14
+ PROJECT_CONTEXT = {
15
+ project_name: "folder_name",
16
+ project_namespace: "FolderName",
17
+ copyright_owner: "<<test_user>>",
18
+ copyright_year: "<<test_year>>",
19
+ }
20
+
21
+ Rake::TestTask.new do |t|
22
+ t.libs << '.' << 'test'
23
+ t.test_files = FileList['test/**/test_*.rb']
24
+ t.verbose = false
25
+ end
26
+
27
+
28
+
29
+ begin
30
+ require 'watch'
31
+ w = `tput cols`.to_i || 80
32
+
33
+ def tty_red(str); "\e[31m#{str}\e[0m" end
34
+ def tty_green(str); "\e[32m#{str}\e[0m" end
35
+ def tty_blink(str); "\e[5m#{str}\e[25m" end
36
+ def tty_reverse_color(str); "\e[7m#{str}\e[27m" end
37
+
38
+
39
+ desc 'Run unit tests everytime a source or test file is changed'
40
+ task :autotest do
41
+ Watch.new( '**/*.rb' ) do
42
+ success = system "clear && rake test"
43
+
44
+ puts tty_green( "-" * w ) if success
45
+ puts tty_reverse_color(tty_red( "-" * w )) if !success
46
+ end
47
+ end
48
+
49
+ desc 'Alias for rake autotest'
50
+ task watch: [:autotest]
51
+
52
+ rescue LoadError
53
+ puts "'rake autotest' unavailable"
54
+ end
55
+
56
+ task default: [:test, :build]
@@ -0,0 +1,27 @@
1
+ # =============================================================================
2
+ #
3
+ # MODULE : test/_test_env.rb
4
+ # PROJECT : FolderName
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) <<test_year>>, <<test_user>>. 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/folder_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
@@ -0,0 +1,23 @@
1
+ # =============================================================================
2
+ #
3
+ # MODULE : test/test_version.rb
4
+ # PROJECT : FolderName
5
+ # DESCRIPTION :
6
+ #
7
+ # Copyright (c) <<test_year>>, <<test_user>>. All rights reserved.
8
+ # =============================================================================
9
+
10
+
11
+ require '_test_env.rb'
12
+
13
+ module FolderName
14
+
15
+ describe Version do
16
+ subject { VERSION }
17
+
18
+ it "is definied as a string" do
19
+ subject.must_be_instance_of String
20
+ end
21
+ end
22
+
23
+ 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/