up_and_running 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 +4 -4
- data/README.md +7 -7
- data/bin/unr +19 -1
- data/lib/up_and_running/compiler.rb +11 -8
- data/lib/up_and_running/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d60a6c8da3cfa807e2d05c56019107195077521f
|
4
|
+
data.tar.gz: a501e53efe3c6a7c68ae887ca513e2d7b25edb1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d20817fb36e43e6fff9c1912e91dd33ae083db2ffcd5ca7d29b83130fe9f5565955300767ceacc0b93ada0e78719a402a8da3be60769e007186200b598ffcd3
|
7
|
+
data.tar.gz: 75075cc627eaa1bbc4564c30988a1506155bc388ad4da9e54634931113322a5161f89f9409fa66e984721cb4147447e6fa99f8673470bb91a92dff265af5bb97
|
data/README.md
CHANGED
@@ -28,20 +28,20 @@ Here is a sample:
|
|
28
28
|
|
29
29
|
```rb
|
30
30
|
# ~/.up_and_running/sample.rb
|
31
|
-
class Sample < UpAndRunning::Compiler
|
32
|
-
def initialize
|
33
|
-
@scope = OpenStruct.new(username: 'jbodah')
|
34
|
-
end
|
35
|
-
end
|
31
|
+
class Sample < UpAndRunning::Compiler; end
|
36
32
|
|
37
33
|
# ~/.up_and_running/sample/hello.erb
|
38
34
|
Hello <%= username %>
|
39
35
|
```
|
40
36
|
|
41
|
-
Then you can just call the `unr` command with the name of your
|
37
|
+
Then you can just call the `unr` command with the name of your feature.
|
38
|
+
The `-s` option takes a comma-separated list of `=` separated key-value pairs
|
39
|
+
which will be merged into the scope used to compile the templates.
|
40
|
+
There is also a `-o` option which can be used to specify the output directory
|
41
|
+
for the compiled templates (uses current directory by default)
|
42
42
|
|
43
43
|
```rb
|
44
|
-
unr sample
|
44
|
+
unr sample -s username=jbodah
|
45
45
|
```
|
46
46
|
|
47
47
|
This will compile the templates and output them into your output directory:
|
data/bin/unr
CHANGED
@@ -5,10 +5,28 @@ raise 'Usage: unr <FEATURE_NAME>' if ARGV.empty?
|
|
5
5
|
$: << File.expand_path('../../lib', __FILE__)
|
6
6
|
require 'up_and_running'
|
7
7
|
|
8
|
+
# TODOD use internal class
|
9
|
+
scope = OpenStruct.new
|
10
|
+
out = '.'
|
11
|
+
|
8
12
|
feature_name = ARGV[0]
|
9
13
|
|
14
|
+
# TODO - use thor and add comments
|
15
|
+
|
16
|
+
# parse opts
|
17
|
+
options = ARGV[1..-1]
|
18
|
+
options.each_slice(2) do |opt, val|
|
19
|
+
case opt
|
20
|
+
when '-s'
|
21
|
+
val.split(',').map {|s| s.split('=')}.each {|k,v| scope.send("#{k}=", v)}
|
22
|
+
when '-o'
|
23
|
+
# TODO untested
|
24
|
+
out = val
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
10
28
|
feature_class = UpAndRunning::FeatureResolver.resolve(feature_name)
|
11
|
-
feature = feature_class.new
|
29
|
+
feature = feature_class.new(scope, out)
|
12
30
|
feature.before_compile
|
13
31
|
feature.compile
|
14
32
|
feature.after_compile
|
@@ -13,6 +13,13 @@ module UpAndRunning
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
# @param scope - evaluation context for ERB templates
|
17
|
+
# @param out - directory to output the compiled templates
|
18
|
+
def initialize(scope, out)
|
19
|
+
@scope = scope
|
20
|
+
@out = out
|
21
|
+
end
|
22
|
+
|
16
23
|
def before_compile; end
|
17
24
|
|
18
25
|
def compile
|
@@ -26,7 +33,7 @@ module UpAndRunning
|
|
26
33
|
|
27
34
|
def copy_dir
|
28
35
|
require 'fileutils'
|
29
|
-
FileUtils.cp_r dir.path + '/.', out
|
36
|
+
FileUtils.cp_r dir.path + '/.', @out
|
30
37
|
end
|
31
38
|
|
32
39
|
def compile_erb?
|
@@ -37,17 +44,13 @@ module UpAndRunning
|
|
37
44
|
require 'erb'
|
38
45
|
require 'tilt'
|
39
46
|
require 'fileutils'
|
40
|
-
Dir[File.join(out, '**/*.erb')].each do |erb_template|
|
41
|
-
|
42
|
-
File.open(erb_template.sub(/\.erb$/, ''), 'w') {|f| f.write
|
47
|
+
Dir[File.join(@out, '**/*.erb')].each do |erb_template|
|
48
|
+
output = Tilt.new(erb_template).render(scope)
|
49
|
+
File.open(erb_template.sub(/\.erb$/, ''), 'w') {|f| f.write output}
|
43
50
|
FileUtils.rm(erb_template)
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
|
-
def out
|
48
|
-
'.'
|
49
|
-
end
|
50
|
-
|
51
54
|
def dir
|
52
55
|
@dir ||= begin
|
53
56
|
dir = Compiler.path_of(self.class).sub(/\.rb/, '')
|