dupler 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbdffb17321666919551924b96c790fb5e0c180eedcbb825a48658842dfdf055
4
- data.tar.gz: bea5611c45ea867a8450649f8b274788402d0f7bef00b158a32d44a3105d55b6
3
+ metadata.gz: f25690fc8eca0630d5f307e6196c58ca182d1959f005fdb5f17d5883d44db82d
4
+ data.tar.gz: 5a05b9731ac6199ea01c3131df6b4276ad4db68c34b32d50f40f1735ef3eeca2
5
5
  SHA512:
6
- metadata.gz: 5e839db91cc365340aecc60193e0113195bc6cff7d2a1b3b2ff09c2a4c850bfc9825792601502e8825fd6e0325a7e1f8a1eca3031a82548467e5038648311c0d
7
- data.tar.gz: 4fb5e091cdee6423e51b601857911e261fbd56aac8065e342a1c55bc4e5cd9bb15a3b56480ceb885d3479c4e8f5ab2a3cfa41fd5a595c6ae301ac8abe391a1dc
6
+ metadata.gz: be1aa337f59deaaec0c07df0166159bfe438f64ed24029a950de817468d56f6c3ae44c8f58d7a88d374bd5c77a0929e1a62a4ebeba933d5ff072deb5bb13656a
7
+ data.tar.gz: 919bf0d23b8d4dd06ae1823d841c6d50569c6da03ed1b250075fa34e182a088c9178d1bef31509e581fec67426a1e8715275eece4651a972e647c852e2be5370
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- output
9
+ output
10
+ Gemfile.lock
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.5
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+
4
+ ## [0.2.0] - 2022-11-03
5
+
6
+ - Remove dependencies for Gemfile/Bundler on runtime
7
+ - Enhance error handling
8
+ - Add --version/-v option to show the version of dupler
9
+
3
10
  ## [0.1.0] - 2021-06-10
4
11
 
5
12
  - Initial release
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 provides you a simple command line interface to document generation environment using template engine especially in ERB format.
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 `Tilt` template engine.
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 is the example of Dupler config file (values.yaml) and template in ERB format.
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 provides you a simple command line interface to document generation environment using template engine especially in ERB format."
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.4.0"
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
- #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
- #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
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('./exe/*').map { |f| File.basename(f) }
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
- lib = File.expand_path('../../lib', __FILE__)
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 'rubygems'
6
- require 'dupler'
7
+ require "rubygems"
8
+ require "dupler"
7
9
 
8
10
  begin
9
11
  Dupler::Cli.start
10
- rescue Dupler::DuplerException => ex
11
- $stderr.puts ex.message
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
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
- require 'json'
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
- @@defalut_conf_name = "./values.yaml"
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
- def build(output_dir = "./output", *template_files)
22
- if template_files.empty?
23
- templates_dir = './templates'
24
- if !Dir.exists?(templates_dir)
25
- raise DuplerException.new("No such template directory: #{templates_dir}")
26
- end
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
- Dir.glob(File.join(templates_dir, '*')) do |f|
29
- template_files << f
30
- end
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
- files = Dir.glob(File.join(f, '*'))
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
- values_file_path = options['conf'] || @@defalut_conf_name
44
- if !File.exists? values_file_path
45
- raise DuplerException.new("No such conf file: #{values_file_path}")
46
- end
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
- core = Dupler::Core.new
49
- core.build(values_file_path, output_dir, extract_template_files)
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
- require 'tilt'
2
- require 'yaml'
3
- require 'hashie'
4
- require 'fileutils'
5
- require 'active_support/all'
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::home, "project_template/*")
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
- if formats
18
- formats.each do |key, value|
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.load File.read(values_file_path)
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
- template = Tilt.new(template_path)
47
- output = template.render(self, config)
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dupler
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.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: 2021-06-19 00:00:00.000000000 Z
11
+ date: 2023-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
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: tilt
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: yaml
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: hashie
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: activesupport
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 provides you a simple command line interface to document generation
84
- environment using template engine especially in ERB format.
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
- post_install_message:
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.4.0
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.1.6
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: []
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "dupler"