file_templater 0.1.2 → 0.1.3
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/lib/file_templater/options_handler.rb +15 -4
- data/lib/file_templater/template.rb +11 -7
- data/lib/file_templater/variables.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d26fcfa5bc5fb8b356afa2803cddad03908ce16
|
4
|
+
data.tar.gz: bfbcc29e18036c6a71d24aafd490854024827d86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 726515a8ba6d89ed7f1fa06ae0c41ab6e3ee1a877e7ba701fc85c40311087664baaecec67b5dae7805d8c4b16ca73675c98653c1819e11e3d1978d39aadfff0d
|
7
|
+
data.tar.gz: 8f4607d540d012e4dfa3d648e46a855e18a1a76d0a992138f57d2d87ffdf00aaa908e6daf6c50f7bb10952175bd374c26259d930421fdd6d9e55863043a76161
|
@@ -9,7 +9,7 @@ module FileTemplater
|
|
9
9
|
|
10
10
|
@actions = []
|
11
11
|
|
12
|
-
parser = OptionParser.new do |o|
|
12
|
+
@parser = OptionParser.new do |o|
|
13
13
|
o.banner = "Usage: template [options] [binding arguments]"
|
14
14
|
|
15
15
|
o.separator ""
|
@@ -67,7 +67,7 @@ module FileTemplater
|
|
67
67
|
o.on_tail("-v", "--version", "Display the version") do
|
68
68
|
puts "File Templater (template) version " + VERSION
|
69
69
|
puts
|
70
|
-
puts "Copyright (C) 2015 Sam Craig"
|
70
|
+
puts "Copyright (C) 2015-2016 Sam Craig"
|
71
71
|
puts "Licensed under the GNU General Public License version 3."
|
72
72
|
|
73
73
|
exit
|
@@ -80,11 +80,22 @@ module FileTemplater
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
if argv.empty?
|
84
|
+
puts @parser
|
85
|
+
exit
|
86
|
+
else
|
87
|
+
@parser.parse!(argv)
|
88
|
+
@arguments = argv
|
89
|
+
end
|
85
90
|
end
|
86
91
|
|
87
92
|
def process_actions
|
93
|
+
if @actions.empty?
|
94
|
+
puts @parser
|
95
|
+
puts "\nNo actions were supplied to the program! The program will not do anything as a result."
|
96
|
+
exit
|
97
|
+
end
|
98
|
+
|
88
99
|
# All actions should be unique.
|
89
100
|
@actions.uniq!
|
90
101
|
|
@@ -4,6 +4,7 @@ module FileTemplater
|
|
4
4
|
# bind: which binding rather than the default to use
|
5
5
|
# nomodify: if the template ERB will be loaded or not
|
6
6
|
def initialize(template, arguments, options = {})
|
7
|
+
@name = template
|
7
8
|
@nomodify = options[:nomodify]
|
8
9
|
|
9
10
|
@template = File.join(HUBS[:template], template)
|
@@ -23,18 +24,20 @@ module FileTemplater
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def load(folder = @template)
|
26
|
-
|
27
|
+
unless folder == @template
|
28
|
+
FileUtils.mkdir(File.join(Dir.pwd, File.basename(folder)))
|
29
|
+
puts "Created folder #{File.join(Dir.pwd, File.basename(folder))}"
|
30
|
+
end
|
27
31
|
|
28
32
|
FileActions.unique_directory_list(folder).each do |f|
|
29
|
-
# We need the whole path to f, but we will keep the short name.
|
30
|
-
short_name = f
|
31
33
|
f = File.join(folder, f)
|
34
|
+
short_path = f.gsub(HUBS[:template] + File::SEPARATOR + @name, "")
|
32
35
|
|
33
36
|
if File.directory?(f)
|
34
37
|
self.load f
|
35
38
|
else
|
36
39
|
if !@nomodify && f.end_with?(".erb")
|
37
|
-
output_file = File.open(File.join(Dir.pwd, transform_file_name(
|
40
|
+
output_file = File.open(File.join(Dir.pwd, transform_file_name(short_path)), "w")
|
38
41
|
|
39
42
|
input_file = File.open(f, "r")
|
40
43
|
output_file.print(ERB.new(input_file.read, nil, "<>").result(@bind && @bind.get_binding))
|
@@ -42,14 +45,15 @@ module FileTemplater
|
|
42
45
|
|
43
46
|
output_file.close
|
44
47
|
else
|
45
|
-
FileUtils.copy_entry(f, File.join(Dir.pwd, transform_file_name(
|
48
|
+
FileUtils.copy_entry(f, File.join(Dir.pwd, transform_file_name(short_path)))
|
46
49
|
end
|
50
|
+
|
51
|
+
puts "Created file #{File.join(Dir.pwd, transform_file_name(short_path))}"
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
56
|
# Expands the variable-in-file-name notation.
|
52
|
-
# file is expected to be a short name
|
53
57
|
def transform_file_name(file)
|
54
58
|
if @bind
|
55
59
|
variables = file.scan(/{{([^}]*)}}/).flatten
|
@@ -59,7 +63,7 @@ module FileTemplater
|
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
62
|
-
!@nomodify && file.end_with?(".erb") ? File.basename(file, ".*") : file
|
66
|
+
(!@nomodify && file.end_with?(".erb") && !File.directory?(file)) ? File.basename(file, ".*") : file
|
63
67
|
end
|
64
68
|
end
|
65
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_templater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Craig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|
@@ -39,7 +39,7 @@ files:
|
|
39
39
|
- lib/file_templater/variables.rb
|
40
40
|
homepage: https://github.com/Sammidysam/file_templater
|
41
41
|
licenses:
|
42
|
-
-
|
42
|
+
- GPL-3.0
|
43
43
|
metadata: {}
|
44
44
|
post_install_message:
|
45
45
|
rdoc_options: []
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
59
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.
|
60
|
+
rubygems_version: 2.5.1
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: A simple system to create files/file structures from ERB templates.
|