up_and_running 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5215284b759d1cb56976b9e2db49e9cfc1e9ec1
4
- data.tar.gz: 22ecdfe28e0a516ea6c7ae8079ea3fd12c2b8ddc
3
+ metadata.gz: d60a6c8da3cfa807e2d05c56019107195077521f
4
+ data.tar.gz: a501e53efe3c6a7c68ae887ca513e2d7b25edb1e
5
5
  SHA512:
6
- metadata.gz: 611bf88549548817892f3a80c509fcffc8cc4d982a3f02a1778489fe11cd525df6e1960bf4d17733dec508210814643e4cfb0fdfee255b4d0603ab44adb040fe
7
- data.tar.gz: 3b14e9d15fb70c08be2b2e6b6cc055706017002bed1eb35a6a0a83275c509749888d42bc6cf517079c56df56d762b786a37f6c98d71e8e5fc1f947c095fc02ea
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
- out = Tilt.new(erb_template).render(scope)
42
- File.open(erb_template.sub(/\.erb$/, ''), 'w') {|f| f.write out}
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/, '')
@@ -1,3 +1,3 @@
1
1
  module UpAndRunning
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: up_and_running
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Bodah