dupler 0.1.0 → 0.2.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 +4 -4
- data/.gitignore +2 -1
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/README.md +5 -5
- data/dupler.gemspec +11 -10
- data/exe/dupler +8 -6
- data/lib/dupler/cli.rb +40 -22
- data/lib/dupler/core.rb +18 -13
- data/lib/dupler/version.rb +1 -1
- data/lib/dupler.rb +2 -3
- metadata +17 -16
- data/project_template/Gemfile +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f25690fc8eca0630d5f307e6196c58ca182d1959f005fdb5f17d5883d44db82d
|
|
4
|
+
data.tar.gz: 5a05b9731ac6199ea01c3131df6b4276ad4db68c34b32d50f40f1735ef3eeca2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be1aa337f59deaaec0c07df0166159bfe438f64ed24029a950de817468d56f6c3ae44c8f58d7a88d374bd5c77a0929e1a62a4ebeba933d5ff072deb5bb13656a
|
|
7
|
+
data.tar.gz: 919bf0d23b8d4dd06ae1823d841c6d50569c6da03ed1b250075fa34e182a088c9178d1bef31509e581fec67426a1e8715275eece4651a972e647c852e2be5370
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# Dupler
|
|
2
2
|
|
|
3
|
-
Easy-to-use template engine driver.
|
|
3
|
+
Easy-to-use template engine driver CLI.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
Dupler
|
|
7
|
+
Dupler is a simple command line interface to generate any kind of text files by using template engine especially in [ERB](https://github.com/ruby/erb) format.
|
|
8
8
|
|
|
9
9
|
Typical use cases are:
|
|
10
10
|
|
|
11
11
|
- generate configuration files for some different environments
|
|
12
12
|
- generate test data
|
|
13
13
|
|
|
14
|
-
Technically dupler is just a cli wrapper of
|
|
15
|
-
And Dupler supports ActiveSupport by default in template.
|
|
14
|
+
Technically dupler is just a cli wrapper of [Tilt](https://github.com/rtomayko/tilt) template engine.
|
|
15
|
+
And Dupler supports [ActiveSupport](https://github.com/rails/rails/tree/main/activesupport) by default in template.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -43,7 +43,7 @@ Or you can specify like below
|
|
|
43
43
|
|
|
44
44
|
## Examples
|
|
45
45
|
|
|
46
|
-
How to write template and values.yaml? Here
|
|
46
|
+
How to write template and values.yaml? Here ar examples of Dupler config files (values.yaml) and templates in ERB format.
|
|
47
47
|
|
|
48
48
|
### values.yaml
|
|
49
49
|
|
data/dupler.gemspec
CHANGED
|
@@ -8,17 +8,18 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.authors = ["daixque"]
|
|
9
9
|
spec.email = ["daixque@gmail.com"]
|
|
10
10
|
|
|
11
|
-
spec.summary = "Easy-to-use template engine driver"
|
|
12
|
-
spec.description = "Dupler
|
|
11
|
+
spec.summary = "Easy-to-use template engine driver CLI."
|
|
12
|
+
spec.description = "Dupler is a simple command line interface to generate any kind of text "\
|
|
13
|
+
"files by using template engine especially in ERB format."
|
|
13
14
|
spec.homepage = "https://github.com/daixque/dupler"
|
|
14
15
|
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = ">= 2.
|
|
16
|
+
spec.required_ruby_version = ">= 2.5.0"
|
|
16
17
|
|
|
17
|
-
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
18
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
18
19
|
|
|
19
20
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/daixque/dupler"
|
|
22
|
+
spec.metadata["changelog_uri"] = "https://github.com/daixque/dupler/blob/main/CHANGELOG.md"
|
|
22
23
|
|
|
23
24
|
# Specify which files should be added to the gem when it is released.
|
|
24
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
@@ -26,17 +27,17 @@ Gem::Specification.new do |spec|
|
|
|
26
27
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
28
|
end
|
|
28
29
|
spec.bindir = "exe"
|
|
29
|
-
#spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
-
spec.executables = Dir.glob(
|
|
30
|
+
# spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
31
|
+
spec.executables = Dir.glob("./exe/*").map { |f| File.basename(f) }
|
|
31
32
|
spec.require_paths = ["lib"]
|
|
32
33
|
|
|
33
34
|
# Uncomment to register a new dependency of your gem
|
|
34
35
|
# spec.add_dependency "example-gem", "~> 1.0"
|
|
36
|
+
spec.add_dependency "activesupport"
|
|
37
|
+
spec.add_dependency "hashie"
|
|
35
38
|
spec.add_dependency "thor"
|
|
36
39
|
spec.add_dependency "tilt"
|
|
37
40
|
spec.add_dependency "yaml"
|
|
38
|
-
spec.add_dependency "hashie"
|
|
39
|
-
spec.add_dependency "activesupport"
|
|
40
41
|
|
|
41
42
|
# For more information and examples about making a new gem, checkout our
|
|
42
43
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/exe/dupler
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
lib = File.expand_path("../lib", __dir__)
|
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
6
|
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
+
require "rubygems"
|
|
8
|
+
require "dupler"
|
|
7
9
|
|
|
8
10
|
begin
|
|
9
11
|
Dupler::Cli.start
|
|
10
|
-
rescue Dupler::DuplerException =>
|
|
11
|
-
|
|
12
|
+
rescue Dupler::DuplerException => e
|
|
13
|
+
warn e.message
|
|
12
14
|
exit 1
|
|
13
|
-
end
|
|
15
|
+
end
|
data/lib/dupler/cli.rb
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "thor"
|
|
4
|
+
require "json"
|
|
5
5
|
require "dupler/core"
|
|
6
6
|
|
|
7
7
|
module Dupler
|
|
8
|
+
# CLI class for dupler command based Thor
|
|
8
9
|
class Cli < Thor
|
|
9
|
-
|
|
10
|
+
DEFAULT_CONF_PATH = "./values.yaml"
|
|
10
11
|
|
|
11
12
|
default_command :build
|
|
12
13
|
|
|
@@ -18,35 +19,52 @@ module Dupler
|
|
|
18
19
|
|
|
19
20
|
desc :build, "build documents."
|
|
20
21
|
option "conf", aliases: "c", type: :string
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
option "version", aliases: "v", type: :boolean
|
|
23
|
+
def build(output_dir = "./output", *template_path)
|
|
24
|
+
if options["version"]
|
|
25
|
+
puts "dupler #{Dupler::VERSION}"
|
|
26
|
+
return
|
|
27
|
+
end
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
extracted_template_files = extract_template_files(template_path)
|
|
30
|
+
|
|
31
|
+
values_file_path = options["conf"] || DEFAULT_CONF_PATH
|
|
32
|
+
raise DuplerException, "No such conf file: #{values_file_path}" unless File.exist? values_file_path
|
|
33
|
+
|
|
34
|
+
core = Dupler::Core.new
|
|
35
|
+
begin
|
|
36
|
+
core.build(values_file_path, output_dir, extracted_template_files)
|
|
37
|
+
rescue Errno::EACCES => e
|
|
38
|
+
raise DuplerException.new(e)
|
|
31
39
|
end
|
|
32
|
-
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def extract_template_files(template_path)
|
|
45
|
+
template_files = find_template_files(template_path)
|
|
46
|
+
|
|
33
47
|
extract_template_files = []
|
|
34
48
|
template_files.each do |f|
|
|
35
49
|
if File.directory?(f)
|
|
36
|
-
|
|
37
|
-
extract_template_files.concat files
|
|
50
|
+
extract_template_files.concat Dir.glob(File.join(f, "*"))
|
|
38
51
|
else
|
|
39
52
|
extract_template_files << f
|
|
40
53
|
end
|
|
41
54
|
end
|
|
55
|
+
extract_template_files
|
|
56
|
+
end
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
if
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
def find_template_files(template_files)
|
|
59
|
+
if template_files.empty?
|
|
60
|
+
templates_dir = "./templates"
|
|
61
|
+
raise DuplerException, "No such template directory: #{templates_dir}" unless Dir.exist?(templates_dir)
|
|
47
62
|
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
Dir.glob(File.join(templates_dir, "*")) do |f|
|
|
64
|
+
template_files << f
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
template_files
|
|
50
68
|
end
|
|
51
69
|
end
|
|
52
70
|
end
|
data/lib/dupler/core.rb
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "tilt"
|
|
4
|
+
require "yaml"
|
|
5
|
+
require "hashie"
|
|
6
|
+
require "fileutils"
|
|
7
|
+
require "active_support/all"
|
|
6
8
|
|
|
7
9
|
module Dupler
|
|
10
|
+
# Dupler core functions
|
|
8
11
|
class Core
|
|
9
12
|
def new_project(project_name)
|
|
10
13
|
FileUtils.mkdir_p project_name
|
|
11
|
-
project_template_dir = Dir.glob File.join(Dupler
|
|
14
|
+
project_template_dir = Dir.glob File.join(Dupler.home, "project_template/*")
|
|
12
15
|
FileUtils.cp_r(project_template_dir, project_name)
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def setup(config)
|
|
16
19
|
formats = config.dig("Dupler", "time", "format")
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Time::DATE_FORMATS[key.to_sym] = value
|
|
20
|
-
end
|
|
20
|
+
formats&.each do |key, value|
|
|
21
|
+
Time::DATE_FORMATS[key.to_sym] = value
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def build(values_file_path, output_dir, template_files)
|
|
25
|
-
yaml = YAML.
|
|
26
|
+
yaml = YAML.safe_load File.read(values_file_path)
|
|
26
27
|
|
|
27
28
|
setup(yaml)
|
|
28
29
|
yaml.delete("Dupler")
|
|
@@ -43,8 +44,12 @@ module Dupler
|
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
def apply_template(template_path, config)
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
begin
|
|
48
|
+
template = Tilt.new(template_path)
|
|
49
|
+
template.render(self, config)
|
|
50
|
+
rescue Exception => e
|
|
51
|
+
raise DuplerException.new("Template rendering error: [#{template_path}] #{e.message}")
|
|
52
|
+
end
|
|
48
53
|
end
|
|
49
54
|
|
|
50
55
|
def output_file(filepath, content)
|
data/lib/dupler/version.rb
CHANGED
data/lib/dupler.rb
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
require "bundler"
|
|
3
|
-
Bundler.require
|
|
4
2
|
|
|
5
3
|
require "dupler/version"
|
|
6
4
|
require "dupler/cli"
|
|
7
5
|
|
|
6
|
+
# Dupler Module
|
|
8
7
|
module Dupler
|
|
9
8
|
class DuplerException < StandardError; end
|
|
10
|
-
|
|
9
|
+
|
|
11
10
|
def self.home
|
|
12
11
|
@dupler_home = File.join File.dirname(__FILE__), "../"
|
|
13
12
|
end
|
metadata
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dupler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- daixque
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-11-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: activesupport
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
@@ -25,7 +25,7 @@ dependencies:
|
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: hashie
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - ">="
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: thor
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - ">="
|
|
@@ -53,7 +53,7 @@ dependencies:
|
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
56
|
+
name: tilt
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - ">="
|
|
@@ -67,7 +67,7 @@ dependencies:
|
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
70
|
+
name: yaml
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - ">="
|
|
@@ -80,8 +80,8 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
-
description: Dupler
|
|
84
|
-
|
|
83
|
+
description: Dupler is a simple command line interface to generate any kind of text
|
|
84
|
+
files by using template engine especially in ERB format.
|
|
85
85
|
email:
|
|
86
86
|
- daixque@gmail.com
|
|
87
87
|
executables:
|
|
@@ -106,7 +106,6 @@ files:
|
|
|
106
106
|
- lib/dupler/cli.rb
|
|
107
107
|
- lib/dupler/core.rb
|
|
108
108
|
- lib/dupler/version.rb
|
|
109
|
-
- project_template/Gemfile
|
|
110
109
|
- project_template/README.md
|
|
111
110
|
- project_template/templates/sample.md.erb
|
|
112
111
|
- project_template/values.yaml
|
|
@@ -115,7 +114,9 @@ licenses:
|
|
|
115
114
|
- MIT
|
|
116
115
|
metadata:
|
|
117
116
|
homepage_uri: https://github.com/daixque/dupler
|
|
118
|
-
|
|
117
|
+
source_code_uri: https://github.com/daixque/dupler
|
|
118
|
+
changelog_uri: https://github.com/daixque/dupler/blob/main/CHANGELOG.md
|
|
119
|
+
post_install_message:
|
|
119
120
|
rdoc_options: []
|
|
120
121
|
require_paths:
|
|
121
122
|
- lib
|
|
@@ -123,15 +124,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
123
124
|
requirements:
|
|
124
125
|
- - ">="
|
|
125
126
|
- !ruby/object:Gem::Version
|
|
126
|
-
version: 2.
|
|
127
|
+
version: 2.5.0
|
|
127
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
129
|
requirements:
|
|
129
130
|
- - ">="
|
|
130
131
|
- !ruby/object:Gem::Version
|
|
131
132
|
version: '0'
|
|
132
133
|
requirements: []
|
|
133
|
-
rubygems_version: 3.
|
|
134
|
-
signing_key:
|
|
134
|
+
rubygems_version: 3.3.3
|
|
135
|
+
signing_key:
|
|
135
136
|
specification_version: 4
|
|
136
|
-
summary: Easy-to-use template engine driver
|
|
137
|
+
summary: Easy-to-use template engine driver CLI.
|
|
137
138
|
test_files: []
|
data/project_template/Gemfile
DELETED