file_templater 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/template +0 -1
- data/lib/file_templater/file_actions.rb +12 -7
- data/lib/file_templater/template.rb +9 -5
- data/lib/file_templater/variables.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: accf9f58ab6f84930e53742a1c5bb5f07cd96b6b
|
4
|
+
data.tar.gz: 06b7c96c3d4379b98a4bfc27c4b0b83ae9b5bb50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08bf8f2095240e726dfad6a33ccb6d3232fbd1050b230453ec670f48bd6814b8718a960543836b4181e509b10d4954ef761bccb769d6c512d2cf65cd4983ce7f
|
7
|
+
data.tar.gz: 2730f4c54516521f891b75e845d939bd16f405543f18fba51f17094fa9035424e33214a02cc5d93e1011c123f253b574f12c12da013c4329596bb6833abc7c96
|
data/bin/template
CHANGED
@@ -7,7 +7,6 @@ $LOAD_PATH.unshift(lib_directory) unless $LOAD_PATH.map { |directory| File.expan
|
|
7
7
|
require "file_templater"
|
8
8
|
|
9
9
|
FileTemplater::FileActions.create_hub_if_necessary
|
10
|
-
FileTemplater::FileActions.require_all_bindings
|
11
10
|
|
12
11
|
handler = FileTemplater::OptionsHandler.new(ARGV)
|
13
12
|
handler.process_actions
|
@@ -115,15 +115,20 @@ module FileTemplater
|
|
115
115
|
unique_directory_list(HUBS[:binding])
|
116
116
|
end
|
117
117
|
|
118
|
-
|
119
|
-
|
120
|
-
unique_directory_list(HUBS[:binding]).each do |f|
|
121
|
-
if f.end_with?(".rb")
|
122
|
-
require File.join(HUBS[:binding], f)
|
123
|
-
end
|
124
|
-
end
|
118
|
+
def require_binding(bind)
|
119
|
+
require File.join(HUBS[:binding], bind)
|
125
120
|
end
|
126
121
|
|
122
|
+
# Returns the first class name in file.
|
123
|
+
def get_class_name(file)
|
124
|
+
File.open(file, "r").each do |line|
|
125
|
+
# The name will be the second word of the class statement.
|
126
|
+
if line.lstrip.start_with?("class ")
|
127
|
+
return line.split(" ")[1]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
127
132
|
def unique_directory_list(path)
|
128
133
|
Dir.entries(path).reject { |d| d == "." || d == ".." }
|
129
134
|
end
|
@@ -8,19 +8,23 @@ module FileTemplater
|
|
8
8
|
|
9
9
|
@template = File.join(HUBS[:template], template)
|
10
10
|
binding_string = options[:bind] || template + ".rb"
|
11
|
-
|
11
|
+
binding_file = File.join(HUBS[:binding], binding_string)
|
12
|
+
using_binding = File.exist?(binding_file)
|
12
13
|
|
13
14
|
if using_binding
|
14
|
-
|
15
|
+
# Load the binding.
|
16
|
+
FileActions.require_binding(binding_string)
|
15
17
|
|
16
|
-
#
|
17
|
-
|
18
|
-
binding_class = Object.const_get(
|
18
|
+
# Get the binding class name from the binding file,
|
19
|
+
# and create an instance of it.
|
20
|
+
binding_class = Object.const_get("Bindings::" + FileActions.get_class_name(binding_file))
|
19
21
|
@bind = binding_class.new(*arguments)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
def load(folder = @template)
|
26
|
+
FileUtils.mkdir(File.basename(folder)) unless folder == @template
|
27
|
+
|
24
28
|
FileActions.unique_directory_list(folder).each do |f|
|
25
29
|
# We need the whole path to f, but we will keep the short name.
|
26
30
|
short_name = f
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Craig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|