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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d257cfba2b31bcafaee4785008f68e5d187401c2
4
- data.tar.gz: c41333e40ac118c6abd00c45dd75ebd352ac7588
3
+ metadata.gz: accf9f58ab6f84930e53742a1c5bb5f07cd96b6b
4
+ data.tar.gz: 06b7c96c3d4379b98a4bfc27c4b0b83ae9b5bb50
5
5
  SHA512:
6
- metadata.gz: 70fd4f23174142d21e63fda267855c60501945b18167cdc79705f98859c11f19bf89a88d65797f82e032adb26ee458b1aa8bcbdefb7215526f55c4e3ba996697
7
- data.tar.gz: 629360b5ef0856d50a4438d48734ab6657699acd0028292141f1bd6fc2b47e4f554828298e9cd930f019343423c81dfea6b4b67c2835af69c683467b06e5dcda
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
- # Requires all of the .rb files in HUBS[:binding].
119
- def require_all_bindings
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
- using_binding = File.exist?(File.join(HUBS[:binding], binding_string))
11
+ binding_file = File.join(HUBS[:binding], binding_string)
12
+ using_binding = File.exist?(binding_file)
12
13
 
13
14
  if using_binding
14
- binding_string = File.basename(binding_string, ".*")
15
+ # Load the binding.
16
+ FileActions.require_binding(binding_string)
15
17
 
16
- # Convert binding_string to a class object.
17
- binding_string = "Bindings::" + binding_string.split("_").map { |w| w.capitalize }.join
18
- binding_class = Object.const_get(binding_string)
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
@@ -1,5 +1,5 @@
1
1
  module FileTemplater
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
 
4
4
  # The hub is where we store our templates and bindings.
5
5
  HUBS = {
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.0
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-24 00:00:00.000000000 Z
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: terminal-table