drudje 0.0.1 → 0.0.2
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/bin/drudje +24 -4
- data/lib/drudje.rb +22 -10
- 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: 4d18f1710e19364a61e8fbf2d1b5a63bf7b85617
|
4
|
+
data.tar.gz: e6ed2dcb60ee5894f00fe3af0c479ea30c07b652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfb544a364727d2fed4c1b62b573c83aad27f24c58ea5e10c0b680bff80d47454014f734e3f65d18a9e878e44443ab4798671bd8330634e819812e9eef7ff50f
|
7
|
+
data.tar.gz: c918cd58c6c3613041c9be1fb06dc2365d73ffc6520967dc9ecf86786cb089c5c31493012c8a04f36a85e93ab3af5f1bbc8e538bcaf8cebabdba1c9740fc121f
|
data/bin/drudje
CHANGED
@@ -1,11 +1,31 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require 'optparse'
|
3
3
|
require_relative '../lib/drudje.rb'
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = 'Usage: drudje [options] source-dir dest-dir'
|
8
|
+
|
9
|
+
opts.on('-l lib-dir', '--lib', 'Use template library') do |l|
|
10
|
+
options[:lib] = l
|
11
|
+
end
|
12
|
+
options[:recursive] = false
|
13
|
+
opts.on('-r', '--recursive', 'Recursive') do |r|
|
14
|
+
options[:recursive] = r
|
15
|
+
end
|
16
|
+
options[:extension] = 'html'
|
17
|
+
opts.on('-e' '--extension', 'File extension to handle') do |e|
|
18
|
+
options[:extension] = e
|
19
|
+
end
|
20
|
+
end.parse!
|
21
|
+
|
22
|
+
puts options
|
4
23
|
src = ARGV[0]
|
5
24
|
dest = ARGV[1]
|
6
|
-
ext = ARGV[2] || '.html'
|
7
25
|
|
8
|
-
|
9
|
-
|
26
|
+
extension = options[:extension]
|
27
|
+
pattern = File.join(src, (options[:recursive] ? '**/*.' : '*.') + extension)
|
28
|
+
d = Drudje.new src, dest, extension, options[:lib], pattern
|
29
|
+
puts 'Processing ' + pattern + ' to ' + dest
|
10
30
|
d.run
|
11
31
|
puts 'Done'
|
data/lib/drudje.rb
CHANGED
@@ -3,12 +3,15 @@ require_relative 'drudje_io.rb'
|
|
3
3
|
class Drudje
|
4
4
|
# TODO: Separate file access to separate object
|
5
5
|
# so that we can test everything
|
6
|
-
attr_accessor :src, :dest, :extension, :io
|
7
|
-
def initialize(src, dest, ext)
|
6
|
+
attr_accessor :src, :dest, :extension, :io, :lib, :pattern
|
7
|
+
def initialize(src, dest, ext, lib, pattern)
|
8
|
+
lib = src if lib == nil
|
8
9
|
@extension = ext
|
9
|
-
|
10
|
-
|
10
|
+
@src = src.end_with?('/') ? src.chomp('/') : src
|
11
|
+
@dest = dest.end_with?('/') ? dest.chomp('/') : dest
|
11
12
|
@io = DrudjeIo.new
|
13
|
+
@lib = lib
|
14
|
+
@pattern = pattern || File.join(src, '*.' + extension)
|
12
15
|
end
|
13
16
|
|
14
17
|
def render(template, args)
|
@@ -62,12 +65,20 @@ class Drudje
|
|
62
65
|
|
63
66
|
def template_file(call_str)
|
64
67
|
parts = call_str.strip.partition(/[\s\n\r]+/)
|
65
|
-
File.join self.
|
68
|
+
File.join self.lib, parts[0] + '.' + self.extension
|
66
69
|
end
|
67
70
|
|
68
71
|
def output_file(file)
|
72
|
+
path = File.dirname file
|
73
|
+
if path =~ Regexp.new("\/" + self.src + "\/")
|
74
|
+
destpath = path.gsub Regexp.new("\/" + self.src + "\/"), "/" + self.dest + "/"
|
75
|
+
elsif path =~ Regexp.new("^" + self.src + "\/")
|
76
|
+
destpath = path.gsub Regexp.new("^" + self.src + "\/"), self.dest + "/"
|
77
|
+
else
|
78
|
+
destpath = self.dest
|
79
|
+
end
|
69
80
|
base = File.basename file
|
70
|
-
File.join
|
81
|
+
File.join destpath, base
|
71
82
|
end
|
72
83
|
|
73
84
|
def expand(call_str)
|
@@ -90,13 +101,14 @@ class Drudje
|
|
90
101
|
end
|
91
102
|
|
92
103
|
def run
|
93
|
-
|
94
|
-
|
104
|
+
files = Dir.glob(self.pattern)
|
105
|
+
puts "No files found matching " + self.pattern.to_s if files.length == 0
|
95
106
|
files.each do |file|
|
96
|
-
|
107
|
+
outfile = output_file(file)
|
108
|
+
puts 'Processing file ' + file + ' to ' + outfile
|
97
109
|
contents = self.io.read file
|
98
110
|
processed = process contents
|
99
|
-
self.io.write
|
111
|
+
self.io.write outfile, processed
|
100
112
|
end
|
101
113
|
end
|
102
114
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drudje
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian DeJong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple text file templating tool
|
14
14
|
email: brian.dejong@gmail.com
|