erberize 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/erberize +26 -0
- data/lib/hash_bindings.rb +26 -0
- metadata +56 -0
data/bin/erberize
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
require 'erb'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
require 'hash_bindings'
|
7
|
+
hash = ARGV.inject({}) do |h, e|
|
8
|
+
if /--([^=]+)=(.*)$/ =~ e
|
9
|
+
h[$1.dup.to_sym] = $2.dup
|
10
|
+
end
|
11
|
+
h
|
12
|
+
end
|
13
|
+
|
14
|
+
options = HashBindings.new(hash)
|
15
|
+
|
16
|
+
erb = ERB.new(File.read(ARGV[0]), 0, "%<>")
|
17
|
+
|
18
|
+
result = erb.result(options.get_binding)
|
19
|
+
if options.missing_bindings?
|
20
|
+
$stderr.puts "Missing bindings: #{options.missing_bindings.inspect}"
|
21
|
+
exit(-1)
|
22
|
+
else
|
23
|
+
File.open(ARGV[1], "wb") do |f|
|
24
|
+
f.print(result)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class HashBindings
|
2
|
+
def initialize(hash)
|
3
|
+
@hash = hash
|
4
|
+
@missed_bindings = []
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_binding
|
8
|
+
binding
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(key)
|
12
|
+
if @hash.include?(key)
|
13
|
+
@hash[key]
|
14
|
+
else
|
15
|
+
@missed_bindings << key
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def missing_bindings?
|
20
|
+
!@missed_bindings.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def missing_bindings
|
24
|
+
@missed_bindings
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erberize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors: []
|
7
|
+
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-11 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Fun with erb
|
17
|
+
email:
|
18
|
+
executables:
|
19
|
+
- erberize
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- bin/erberize
|
26
|
+
- lib/hash_bindings.rb
|
27
|
+
has_rdoc: true
|
28
|
+
homepage:
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.3.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Fun with erb
|
55
|
+
test_files: []
|
56
|
+
|