ryonan 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b22e3dd93799920ad581760455f2e73cef58e59
4
+ data.tar.gz: 1f9d53280c1106cb89e09ac1449179b67dd7c3ec
5
+ SHA512:
6
+ metadata.gz: e1d0304f0456fe74852b198bdbc3947375fb0307f9827e2756541d138b32b9f13378f696802f25c34f1f4f3db1fd2bc9da74353d30a96e645704eb2623086512
7
+ data.tar.gz: 1ce028afe4f4d7305b18493918b8cb2a34ff3e6d05f3e40686dff619ef94ae08d082cf91a7c42708b5f0257ab2e87f19a855afea2def3ea9e62a8d4ce43d41f4
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ryonan.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 yuki_yano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # Ryonan
2
+
3
+ Ryonan is a tool to make simple skeleton.
4
+
5
+ It make from template directory and erb, and interactively operation.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ryonan'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ryonan
22
+
23
+ ## Usage
24
+
25
+ Create a directory named `.template` and file named `.template/.config`.
26
+
27
+ `.template` is replicated and `.config` is used to set variables in interactive command.
28
+
29
+ - `variable_name = 'value'`
30
+ - Directory `__variable_name__` > `value`
31
+ - File `__variable_name__.rb` > `value.rb`
32
+ - Erb File `__variable_name__.rb.erb` > `value.rb` and render erb
33
+
34
+ ```
35
+ $ tree -a
36
+ .
37
+ └── template1
38
+ └── .template
39
+ ├── .config
40
+ ├── __dir__
41
+ │   └── sample2.rb
42
+ ├── __sample__.rb.erb
43
+ └── dir2
44
+
45
+ $ cat template1/.template/.config
46
+ sample=Sample
47
+ dir
48
+ method_name
49
+
50
+ $ cat template1/.template/__sample__.rb.erb
51
+ class <%= sample %>
52
+ def method1; end
53
+ def <%= method_name %>; end
54
+ end
55
+
56
+
57
+ $ ryonan
58
+ Template List
59
+ [0] : './template1'
60
+
61
+ Select Template[*] -> 0
62
+ Input the destination directory name -> test_template
63
+ Set the value to the variable in the template
64
+ sample (Default:Sample) ->
65
+ dir -> dir1
66
+ method_name -> method_name1
67
+ I, [2015-03-05T06:58:26.892198 #50253] INFO -- : cp -r ./template1/.template ./template1/test_template
68
+ I, [2015-03-05T06:58:26.894241 #50253] INFO -- : rm ./template1/test_template/.config
69
+ I, [2015-03-05T06:58:26.894626 #50253] INFO -- : mv ./template1/test_template/__sample__.rb.erb ./template1/test_template/Sample.rb.erb
70
+ I, [2015-03-05T06:58:26.895136 #50253] INFO -- : mv ./template1/test_template/__dir__ ./template1/test_template/dir1
71
+ I, [2015-03-05T06:58:26.897876 #50253] INFO -- : render_erb ./template1/test_template/Sample.rb.erb to ./template1/test_template/Sample.rb
72
+ I, [2015-03-05T06:58:26.898089 #50253] INFO -- : rm ./template1/test_template/Sample.rb.erb
73
+
74
+ $ tree template1/test_template/
75
+ template1/test_template/
76
+ ├── Sample.rb
77
+ ├── dir1
78
+ │   └── sample2.rb
79
+ └── dir2
80
+
81
+ $ cat template1/test_template/Sample.rb
82
+ class Sample
83
+ def method1; end
84
+ def method_name1; end
85
+ en
86
+
87
+ ```
88
+
89
+ ## Template candidate
90
+
91
+ ```
92
+ $ mkdir directory
93
+
94
+ $ cp -r template1/ directory/template2
95
+
96
+ $ ryonan
97
+ Template List
98
+ [0] : './directory/template2'
99
+ [1] : './template1'
100
+
101
+ Select Template[*] -> 0
102
+ Input the destination directory name -> test_template2
103
+ Set the value to the variable in the template
104
+ sample (Default:Sample) -> sample
105
+ dir -> dir
106
+ method_name -> method_name
107
+ I, [2015-03-05T07:00:54.992676 #51451] INFO -- : cp -r ./directory/template2/.template ./directory/template2/test_template2
108
+ I, [2015-03-05T07:00:54.993609 #51451] INFO -- : rm ./directory/template2/test_template2/.config
109
+ I, [2015-03-05T07:00:54.994570 #51451] INFO -- : mv ./directory/template2/test_template2/__sample__.rb.erb ./directory/template2/test_template2/sample.rb.erb
110
+ I, [2015-03-05T07:00:54.997861 #51451] INFO -- : mv ./directory/template2/test_template2/__dir__ ./directory/template2/test_template2/dir
111
+ I, [2015-03-05T07:00:54.998434 #51451] INFO -- : render_erb ./directory/template2/test_template2/sample.rb.erb to ./directory/template2/test_template2/sample.rb
112
+ I, [2015-03-05T07:00:54.998616 #51451] INFO -- : rm ./directory/template2/test_template2/sample.rb.erb
113
+
114
+ $ tree directory/template2/test_template2/
115
+ directory/template2/test_template2/
116
+ ├── dir
117
+ │   └── sample2.rb
118
+ ├── dir2
119
+ └── sample.rb
120
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/ryonan ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ryonan'
4
+
5
+ root_filer = Ryonan::Filer.new('.')
6
+ Ryonan::Interactive.print_template_list(root_filer)
7
+ template_root = Ryonan::Interactive.select_template(root_filer)
8
+ name = Ryonan::Interactive.read_template_name
9
+ variable_hash = Ryonan::Interactive.read_configs(template_root)
10
+
11
+ Ryonan::Template.create(template_root, name, variable_hash)
data/lib/ryonan.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'ryonan/version'
2
+ require 'ryonan/filer'
3
+ require 'ryonan/template'
4
+ require 'ryonan/config'
5
+ require 'ryonan/interactive'
6
+ require 'ryonan/renderer'
@@ -0,0 +1,13 @@
1
+ module Ryonan
2
+ module Config
3
+ class << self
4
+ def template_dir_name
5
+ '.template'
6
+ end
7
+
8
+ def config_file_name
9
+ '.config'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,75 @@
1
+ require 'fileutils'
2
+ require 'logger'
3
+
4
+ module Ryonan
5
+ class Filer
6
+ attr_accessor :root
7
+
8
+ def initialize(root)
9
+ self.root = root
10
+ end
11
+
12
+ def files
13
+ Dir.glob("#{root}/**/*")
14
+ end
15
+
16
+ def dirs
17
+ files.select { |file_path| FileTest.directory?(file_path) }
18
+ end
19
+
20
+ def templatable_dirs
21
+ dirs.select { |dir| Dir::entries(dir).any? { |file| file == '.template' } }
22
+ end
23
+
24
+ def erbs
25
+ files.select { |file_path| file_path.match(/\.erb$/) }
26
+ end
27
+
28
+ def recursive_rename_files(variable_hash)
29
+ variable_hash.each do |key, value|
30
+ from = "__#{key}__"
31
+ while files.any? { |dir| dir.match(/#{from}/) }
32
+ src = files.select { |dir| dir.match(/#{from}/) }.first
33
+ dest = src.gsub(/#{from}/, value)
34
+ Filer.mv(src, dest)
35
+ end
36
+ end
37
+ end
38
+
39
+ def render_erbs(variable_hash)
40
+ erbs.each do |erb|
41
+ Filer.render_erb(erb, variable_hash)
42
+ end
43
+ end
44
+
45
+ class << self
46
+ attr_writer :logger
47
+
48
+ def logger
49
+ @logger ||= Logger.new(STDOUT)
50
+ end
51
+
52
+ def cp_r(src, dest)
53
+ logger.info("cp -r #{src} #{dest}")
54
+ FileUtils.cp_r(src, dest)
55
+ end
56
+
57
+ def mv(src, dest)
58
+ logger.info("mv #{src} #{dest}")
59
+ FileUtils.mv(src, dest)
60
+ end
61
+
62
+ def rm(file)
63
+ logger.info("rm #{file}")
64
+ FileUtils.rm(file)
65
+ end
66
+
67
+ def render_erb(erb, hash)
68
+ result = Renderer.new(hash).render(open(erb).read)
69
+ Filer.logger.info("render_erb #{erb} to #{erb.gsub(/\.erb$/, '')}")
70
+ open(erb.gsub(/\.erb$/, ''), 'w') { |file| file.puts(result) }
71
+ Filer.rm(erb)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,59 @@
1
+ require 'readline'
2
+
3
+ module Ryonan
4
+ module Interactive
5
+ class << self
6
+ def print_template_list(filer)
7
+ puts 'Template List'
8
+ filer.templatable_dirs.map.with_index do |dir, index|
9
+ puts " [#{index}] : '#{dir}'"
10
+ end
11
+ puts ''
12
+ end
13
+
14
+ def select_template(filer)
15
+ select = Readline.readline('Select Template[*] -> ')
16
+ if select.match(/\d+/) && !filer.templatable_dirs[select.to_i].nil?
17
+ filer.templatable_dirs[select.to_i]
18
+ else
19
+ puts 'The specified template does not exist'
20
+ exit 1
21
+ end
22
+ end
23
+
24
+ def read_template_name
25
+ name = Readline.readline('Input the destination directory name -> ')
26
+ if name == Config.template_dir_name
27
+ puts "#{Config.template_dir_name} will overlap with the template directory name"
28
+ exit 1
29
+ else
30
+ name
31
+ end
32
+ end
33
+
34
+ def read_configs(template_root)
35
+ puts 'Set the value to the variable in the template'
36
+ variables = File.open(config_file_path(template_root)).readlines.map(&:chomp)
37
+ variables.map { |line| read_config(line) }.to_h
38
+ end
39
+
40
+ private
41
+
42
+ def config_file_path(template_root)
43
+ "#{template_root}/#{Config.template_dir_name}/#{Config.config_file_name}"
44
+ end
45
+
46
+ def read_config(line)
47
+ if line.match(/.+=/)
48
+ (variable_name, default) = line.split('=')
49
+ input = Readline.readline(" #{variable_name} (Default: #{default}) -> ")
50
+ variable_value = input.empty? ? default : input
51
+ else
52
+ variable_name = line
53
+ variable_value = Readline.readline(" #{variable_name} -> ")
54
+ end
55
+ [variable_name, variable_value]
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,11 @@
1
+ require 'erb'
2
+ require 'ostruct'
3
+ require 'active_support/core_ext/string/inflections'
4
+
5
+ module Ryonan
6
+ class Renderer < OpenStruct
7
+ def render(template)
8
+ ERB.new(template).result(binding)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Ryonan
2
+ class Template
3
+ def self.create(template_root, name, variable_hash)
4
+ Filer.cp_r("#{template_root}/#{Config.template_dir_name}", "#{template_root}/#{name}")
5
+ Filer.rm("#{template_root}/#{name}/#{Config.config_file_name}")
6
+ filer = Filer.new("#{template_root}/#{name}")
7
+ filer.recursive_rename_files(variable_hash)
8
+ filer.render_erbs(variable_hash)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Ryonan
2
+ VERSION = "0.0.1"
3
+ end
data/ryonan.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ryonan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ryonan'
8
+ spec.version = Ryonan::VERSION
9
+ spec.authors = ['tigberd']
10
+ spec.email = ['tigberd@gmail.com']
11
+
12
+ spec.summary = 'Ryonan is a tool to make simple skeleton'
13
+ spec.description = 'Ryonan is a tool to make simple skeleton. It make from template directory and erb, and interactively operation.'
14
+ spec.homepage = 'https://github.com/tigberd/ryonan'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activesupport', '~> 4.2'
22
+ spec.add_development_dependency 'bundler', '~> 1.8'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ryonan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tigberd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Ryonan is a tool to make simple skeleton. It make from template directory
56
+ and erb, and interactively operation.
57
+ email:
58
+ - tigberd@gmail.com
59
+ executables:
60
+ - ryonan
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/ryonan
70
+ - lib/ryonan.rb
71
+ - lib/ryonan/config.rb
72
+ - lib/ryonan/filer.rb
73
+ - lib/ryonan/interactive.rb
74
+ - lib/ryonan/renderer.rb
75
+ - lib/ryonan/template.rb
76
+ - lib/ryonan/version.rb
77
+ - ryonan.gemspec
78
+ homepage: https://github.com/tigberd/ryonan
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Ryonan is a tool to make simple skeleton
102
+ test_files: []