erbside 0.2.1 → 0.3.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.
- data/.ruby +28 -31
- data/HISTORY.rdoc +12 -0
- data/QED.rdoc +353 -0
- data/README.rdoc +8 -4
- data/lib/erbside.yml +28 -31
- data/lib/erbside/metadata.rb +2 -4
- data/qed/00_intro.rdoc +1 -0
- metadata +67 -105
- data/.gemspec +0 -152
- data/.gitignore +0 -8
- data/MANIFEST +0 -34
- data/PROFILE +0 -33
- data/VERSION +0 -1
- data/main.assembly +0 -57
- data/site/.htaccess +0 -2
- data/site/.rsync-filter +0 -7
- data/site/assets/css/highlight.css +0 -96
- data/site/assets/css/reset.css +0 -19
- data/site/assets/css/site.css +0 -52
- data/site/assets/img/curb.jpg +0 -0
- data/site/assets/img/emeraled.png +0 -0
- data/site/assets/img/fade.png +0 -0
- data/site/assets/img/fork-me.png +0 -0
- data/site/assets/img/icon.jpg +0 -0
- data/site/assets/js/highlight.js +0 -1
- data/site/assets/js/jquery.js +0 -19
- data/site/assets/js/jquery.tabs.js +0 -1
- data/site/index.html +0 -229
- data/work/defunct/css/color.css +0 -45
- data/work/defunct/css/font.css +0 -39
- data/work/defunct/css/struct.css +0 -51
- data/work/defunct/inline-old/bash.rb +0 -36
- data/work/defunct/inline-old/cpp.rb +0 -39
- data/work/defunct/inline-old/css.rb +0 -32
- data/work/defunct/inline-old/html.rb +0 -32
- data/work/defunct/inline-old/js.rb +0 -85
- data/work/defunct/inline-old/ruby.rb +0 -147
- data/work/defunct/inline-old/type.rb +0 -91
- data/work/defunct/inline.rb +0 -202
- data/work/defunct/plan.rb +0 -37
- data/work/defunct/tiller.rb +0 -200
- data/work/defunct/webme/options.yml +0 -4
- data/work/defunct/whole.rb +0 -221
- data/work/plugins/syckle/erbside.rb +0 -45
- data/work/radio_earth.jpg +0 -0
- data/yard.watchr +0 -12
@@ -1,91 +0,0 @@
|
|
1
|
-
module Till
|
2
|
-
|
3
|
-
class Inline
|
4
|
-
|
5
|
-
# = Type Base Class
|
6
|
-
#
|
7
|
-
class Type
|
8
|
-
|
9
|
-
# C L A S S - M E T H O D S
|
10
|
-
|
11
|
-
#
|
12
|
-
def self.map
|
13
|
-
@map ||= (
|
14
|
-
Type.register.inject({}) do |hash, base|
|
15
|
-
base.extensions.each do |ext|
|
16
|
-
hash[ext] = base
|
17
|
-
end
|
18
|
-
hash
|
19
|
-
end
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.register
|
24
|
-
@register ||= []
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.inherited(base)
|
28
|
-
register << base
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.extensions ; raise ; end
|
32
|
-
|
33
|
-
|
34
|
-
## A T T R I B U T E S
|
35
|
-
|
36
|
-
#attr :string
|
37
|
-
#attr :indent
|
38
|
-
#attr :front
|
39
|
-
#attr :mark
|
40
|
-
#attr :pad
|
41
|
-
#attr :till
|
42
|
-
#attr :count
|
43
|
-
#attr :body
|
44
|
-
#attr :post
|
45
|
-
|
46
|
-
# Initialize a new type match.
|
47
|
-
#def initialize(opts)
|
48
|
-
# @line = opts[:line]
|
49
|
-
# @indent = opts[:indent]
|
50
|
-
# @front = opts[:front]
|
51
|
-
# @mark = opts[:mark]
|
52
|
-
# @pad = opts[:pad]
|
53
|
-
# @till = opts[:till]
|
54
|
-
# @count = opts[:count].to_i
|
55
|
-
# @body = opts[:body].strip
|
56
|
-
# @post = opts[:post]
|
57
|
-
#end
|
58
|
-
|
59
|
-
## Add a tail line.
|
60
|
-
#def <<(line)
|
61
|
-
# @tail << line
|
62
|
-
#end
|
63
|
-
|
64
|
-
#
|
65
|
-
#def to_s(result, cnt=nil)
|
66
|
-
# if cnt
|
67
|
-
# mark = marker.sub(/\+\d+/, "+#{cnt}")
|
68
|
-
# "#{indent}#{front}#{mark}#{tail}\n" + result + "\n" # TODO: there should be no front
|
69
|
-
# elsif carrot?
|
70
|
-
# b = tail.index('^') + 1
|
71
|
-
# e = tail.index(/[<{]/) || - 1
|
72
|
-
# m = tail[b...e]
|
73
|
-
# i = front.index(m)
|
74
|
-
# result = front[0...i] + result.sub('^','')
|
75
|
-
# "#{indent}#{result}#{marker}#{tail}\n"
|
76
|
-
# else
|
77
|
-
# "#{indent}#{result}#{marker}#{tail}\n"
|
78
|
-
# end
|
79
|
-
#end
|
80
|
-
|
81
|
-
# Is a carrot matcher?
|
82
|
-
def self.carrot?(render)
|
83
|
-
/^\s*\^/.match(render)
|
84
|
-
end
|
85
|
-
|
86
|
-
end#class Type
|
87
|
-
|
88
|
-
end#class Inline
|
89
|
-
|
90
|
-
end#module Till
|
91
|
-
|
data/work/defunct/inline.rb
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
module Till
|
2
|
-
|
3
|
-
# = Inline Templating
|
4
|
-
#
|
5
|
-
class Inline
|
6
|
-
|
7
|
-
# R E Q U I R E M E N T S
|
8
|
-
|
9
|
-
require 'erb'
|
10
|
-
require 'tilt'
|
11
|
-
require 'till/context'
|
12
|
-
|
13
|
-
|
14
|
-
# C O N S T A N T S
|
15
|
-
|
16
|
-
# Supported templating systems.
|
17
|
-
STENCILS = %w{ .erb .liquid .mustache }
|
18
|
-
|
19
|
-
|
20
|
-
# A T T R I B U T E S
|
21
|
-
|
22
|
-
# The file to receive inline templating.
|
23
|
-
attr :file
|
24
|
-
|
25
|
-
# The extname of the file.
|
26
|
-
attr :extension
|
27
|
-
|
28
|
-
# Location of the file.
|
29
|
-
attr :location
|
30
|
-
|
31
|
-
# The rendered result.
|
32
|
-
attr :result
|
33
|
-
|
34
|
-
# Rendering context/scope.
|
35
|
-
attr :context
|
36
|
-
|
37
|
-
# Extension name of stenciling template system
|
38
|
-
# to use. This determines with templating system to use,
|
39
|
-
# such as .erb, .liquid, etc. This defaults to '.erb',
|
40
|
-
# but can be changed in the file with:
|
41
|
-
#
|
42
|
-
# # :till.stencil: <ext>
|
43
|
-
#
|
44
|
-
attr :stencil
|
45
|
-
|
46
|
-
|
47
|
-
# I N I T I A L I Z E
|
48
|
-
|
49
|
-
#
|
50
|
-
def initialize(file)
|
51
|
-
@file = file
|
52
|
-
@extension = File.extname(file)
|
53
|
-
@location = File.dirname(File.expand_path(file))
|
54
|
-
|
55
|
-
self.stencil = '.erb'
|
56
|
-
|
57
|
-
@context = Context.new(@location)
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
def stencil=(ext)
|
62
|
-
ext = (ext[0,1] == '.' ? ext : ".#{ext}")
|
63
|
-
raise "unsupported stencil type -- #{ext}" unless STENCILS.include?(ext)
|
64
|
-
@stencil = ext
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
def root
|
69
|
-
context.metadata.root
|
70
|
-
end
|
71
|
-
|
72
|
-
#
|
73
|
-
def render
|
74
|
-
render_inline(file)
|
75
|
-
end
|
76
|
-
|
77
|
-
#
|
78
|
-
def render_inline(file)
|
79
|
-
#name = file.sub(Dir.pwd+'/', '')
|
80
|
-
save = false
|
81
|
-
text = ''
|
82
|
-
lines = File.readlines(file)
|
83
|
-
i = 0
|
84
|
-
while i < lines.size
|
85
|
-
line = lines[i]
|
86
|
-
if md = /^\s*#\s*:till.stencil:(.*?)/.match(line)
|
87
|
-
self.type = md[1].strip
|
88
|
-
text << line
|
89
|
-
elsif md = /^(\s*)#(\s*):till\+(\d*):/.match(line)
|
90
|
-
temp = md.post_match
|
91
|
-
code = md.post_match
|
92
|
-
line = lines[i+=1]
|
93
|
-
while i < lines.size && line =~ /^\s*^#/
|
94
|
-
temp << line
|
95
|
-
code << line
|
96
|
-
line = lines[i+=1]
|
97
|
-
end
|
98
|
-
res = render_template(code.gsub(/^\s*#*/,'').strip)
|
99
|
-
text << md[1] + "#" + md[2] + ":till+#{res.split("\n").size}:"
|
100
|
-
text << temp
|
101
|
-
text << res
|
102
|
-
text << "\n"
|
103
|
-
save = true
|
104
|
-
i += md[3].to_i
|
105
|
-
elsif md = /^(\s*).*?(\s*#\s*:till:)/.match(line)
|
106
|
-
pm = md.post_match.strip
|
107
|
-
if pm[0,1] == '^'
|
108
|
-
pm = pm[1..-1].strip
|
109
|
-
fm = pm[0...(pm.index('<')||-1)]
|
110
|
-
ri = line.index(fm)
|
111
|
-
if ri
|
112
|
-
text << line[0...ri] + render_template(pm) + md[2] + md.post_match
|
113
|
-
else
|
114
|
-
puts "waning: skipped line #{i} no match for #{fm}"
|
115
|
-
text << line
|
116
|
-
end
|
117
|
-
else
|
118
|
-
text << md[1] + render_template(pm) + md[2] + md.post_match
|
119
|
-
end
|
120
|
-
save = true
|
121
|
-
i += 1
|
122
|
-
else
|
123
|
-
text << line
|
124
|
-
i += 1
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
@result = text
|
129
|
-
end
|
130
|
-
|
131
|
-
#
|
132
|
-
|
133
|
-
def render_template(text)
|
134
|
-
template = Tilt[stencil]
|
135
|
-
unless template
|
136
|
-
warn "unknown template type #{stencil}"
|
137
|
-
template = Tilt::ERBTemplate
|
138
|
-
end
|
139
|
-
render_tilt(template.new{ text })
|
140
|
-
end
|
141
|
-
|
142
|
-
#
|
143
|
-
|
144
|
-
def render_tilt(template)
|
145
|
-
Dir.chdir(location) do
|
146
|
-
template.render(@context)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
#
|
151
|
-
|
152
|
-
def relative_output(dir=nil)
|
153
|
-
dir = dir || Dir.pwd
|
154
|
-
output.sub(dir+'/', '')
|
155
|
-
end
|
156
|
-
|
157
|
-
#
|
158
|
-
|
159
|
-
def exist?
|
160
|
-
File.exist?(output)
|
161
|
-
end
|
162
|
-
|
163
|
-
# Has the file changed?
|
164
|
-
|
165
|
-
def changed?
|
166
|
-
if exist?
|
167
|
-
File.read(output) != result
|
168
|
-
else
|
169
|
-
true
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# Save result to file.
|
174
|
-
|
175
|
-
def save
|
176
|
-
File.open(output, 'w'){ |f| f << result }
|
177
|
-
end
|
178
|
-
|
179
|
-
# Output file (same as the input file).
|
180
|
-
|
181
|
-
def output
|
182
|
-
file
|
183
|
-
end
|
184
|
-
|
185
|
-
#
|
186
|
-
|
187
|
-
#def erb(text, file=nil)
|
188
|
-
# if file
|
189
|
-
# dir = File.dirname(file)
|
190
|
-
# Dir.chdir(dir) do
|
191
|
-
# context.erb(text)
|
192
|
-
# end
|
193
|
-
# else
|
194
|
-
# context.erb(text)
|
195
|
-
# end
|
196
|
-
#end
|
197
|
-
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
|
202
|
-
|
data/work/defunct/plan.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Till
|
2
|
-
|
3
|
-
# = Tilling Plan
|
4
|
-
#
|
5
|
-
# A plan file is used to easily repeat a set of tills.
|
6
|
-
#
|
7
|
-
# myfile.html:
|
8
|
-
# source: templates/myfile.rdoc
|
9
|
-
# filter: erb, rdoc
|
10
|
-
#
|
11
|
-
class Plan
|
12
|
-
|
13
|
-
include Enumerable
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
def initialize(root)
|
18
|
-
file = Dir[File.join(root, '{.config,config}/till/plan.{yml,yaml}')].first
|
19
|
-
@plan = file ? YAML.load(File.new(file) : {}
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
def [](file)
|
25
|
-
@plan[file]
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
|
30
|
-
def each(&block)
|
31
|
-
@plan.each(&block)
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
data/work/defunct/tiller.rb
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
require 'till/metadata'
|
2
|
-
require 'facets/kernel/ask'
|
3
|
-
require 'facets/string/tabto'
|
4
|
-
require 'erb'
|
5
|
-
|
6
|
-
module Till
|
7
|
-
|
8
|
-
# The Tiller class is used to generate files from
|
9
|
-
# embebbded ERB template files.
|
10
|
-
#
|
11
|
-
class Tiller
|
12
|
-
|
13
|
-
attr_accessor :files
|
14
|
-
|
15
|
-
attr_accessor :force
|
16
|
-
|
17
|
-
attr_accessor :skip
|
18
|
-
|
19
|
-
#attr_accessor :delete
|
20
|
-
|
21
|
-
#
|
22
|
-
def initialize(files, options)
|
23
|
-
files = files || Dir['**/*.til']
|
24
|
-
files = files.map do |file|
|
25
|
-
if File.directory?(file)
|
26
|
-
collect_usable_files(file)
|
27
|
-
else
|
28
|
-
file
|
29
|
-
end
|
30
|
-
end.flatten
|
31
|
-
@files = files
|
32
|
-
@force = options[:force]
|
33
|
-
@skip = options[:skip]
|
34
|
-
#@delete = options[:delete]
|
35
|
-
end
|
36
|
-
|
37
|
-
def collect_usable_files(dir)
|
38
|
-
Dir[File.join(dir,'**/*.{till,til,rb}')]
|
39
|
-
end
|
40
|
-
|
41
|
-
def delete? ; @delete ; end
|
42
|
-
def force? ; @force ; end
|
43
|
-
def skip? ; @skip ; end
|
44
|
-
|
45
|
-
def debug? ; $DEBUG ; end
|
46
|
-
def trial? ; $TRIAL ; end
|
47
|
-
|
48
|
-
#
|
49
|
-
#def tillfiles
|
50
|
-
# @tillfiles ||= Dir[File.join(@output, '**/*.till')].select{ |f| File.file?(f) }
|
51
|
-
#end
|
52
|
-
|
53
|
-
#
|
54
|
-
#def rubyfiles
|
55
|
-
# @rubyfiles ||= Dir[File.join(@output, '**/*.rb')].select{ |f| File.file?(f) }
|
56
|
-
#end
|
57
|
-
|
58
|
-
def till
|
59
|
-
files.each{ |file|
|
60
|
-
raise "unsupport file type -- #{file}" unless File.extname =~ /^\.(rb|til|till)$/
|
61
|
-
end
|
62
|
-
|
63
|
-
files.each do |file|
|
64
|
-
case File.extname(file)
|
65
|
-
when '.till', '.til'
|
66
|
-
till_template(file)
|
67
|
-
when '.rb'
|
68
|
-
till_inline(file)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# Search for till templates (*.till) and render.
|
74
|
-
#
|
75
|
-
def till_template(file)
|
76
|
-
result = erb(File.read(file))
|
77
|
-
fname = file.chomp(File.extname(file))
|
78
|
-
write(fname, result)
|
79
|
-
#rm(file) if delete? # TODO
|
80
|
-
end
|
81
|
-
|
82
|
-
# Search through Ruby files for inline till templates.
|
83
|
-
def till_inline(file)
|
84
|
-
name = file.sub(Dir.pwd+'/', '')
|
85
|
-
save = false
|
86
|
-
text = ''
|
87
|
-
lines = File.readlines(file)
|
88
|
-
i = 0
|
89
|
-
while i < lines.size
|
90
|
-
line = lines[i]
|
91
|
-
if md = /^(\s*)#(\s*):till\+(\d*):/.match(line)
|
92
|
-
temp = md.post_match
|
93
|
-
code = md.post_match
|
94
|
-
line = lines[i+=1]
|
95
|
-
while i < lines.size && line =~ /^\s*^#/
|
96
|
-
temp << line
|
97
|
-
code << line
|
98
|
-
line = lines[i+=1]
|
99
|
-
end
|
100
|
-
res = erb(code.gsub(/^\s*#*/,'').strip, file)
|
101
|
-
text << md[1] + "#" + md[2] + ":till+#{res.split("\n").size}:"
|
102
|
-
text << temp
|
103
|
-
text << res
|
104
|
-
text << "\n"
|
105
|
-
save = true
|
106
|
-
i += md[3].to_i
|
107
|
-
elsif md = /^(\s*).*?(\s*#\s*:till:)/.match(line)
|
108
|
-
pm = md.post_match.strip
|
109
|
-
if pm[0,1] == '^'
|
110
|
-
pm = pm[1..-1].strip
|
111
|
-
fm = pm[0...(pm.index('<')||-1)]
|
112
|
-
ri = line.index(fm)
|
113
|
-
if ri
|
114
|
-
text << line[0...ri] + erb(pm, file) + md[2] + md.post_match
|
115
|
-
else
|
116
|
-
puts "waning: skipped line #{i} no match for #{fm}"
|
117
|
-
text << line
|
118
|
-
end
|
119
|
-
else
|
120
|
-
text << md[1] + erb(pm, file) + md[2] + md.post_match
|
121
|
-
end
|
122
|
-
save = true
|
123
|
-
i += 1
|
124
|
-
else
|
125
|
-
text << line
|
126
|
-
i += 1
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
if save
|
131
|
-
write(file, text)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
#
|
136
|
-
def write(fname, text)
|
137
|
-
name = fname.sub(Dir.pwd+'/', '')
|
138
|
-
if trial?
|
139
|
-
puts " #{name}"
|
140
|
-
else
|
141
|
-
if File.exist?(fname)
|
142
|
-
if skip? # TODO: skip before running erb ?
|
143
|
-
puts " skipped #{name}"
|
144
|
-
return
|
145
|
-
elsif File.read(fname) == text
|
146
|
-
puts " unchanged #{name}"
|
147
|
-
return
|
148
|
-
elsif !force?
|
149
|
-
case ask(" overwrite #{name}? ")
|
150
|
-
when 'y', 'yes'
|
151
|
-
else
|
152
|
-
return
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
File.open(fname, 'w'){ |f| f << text }
|
157
|
-
puts " written #{name}"
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
#
|
162
|
-
def context
|
163
|
-
@conext ||= Erb.new() #TODO: @output ?
|
164
|
-
end
|
165
|
-
|
166
|
-
def erb(text, file=nil)
|
167
|
-
if file
|
168
|
-
dir = File.dirname(file)
|
169
|
-
Dir.chdir(dir) do
|
170
|
-
context.erb(text)
|
171
|
-
end
|
172
|
-
else
|
173
|
-
context.erb(text)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
# Tiller's erb context
|
178
|
-
#
|
179
|
-
class Erb
|
180
|
-
|
181
|
-
def initialize(dir=nil)
|
182
|
-
@metadata = Metadata.new(dir)
|
183
|
-
end
|
184
|
-
|
185
|
-
def method_missing(s)
|
186
|
-
@metadata.send(s)
|
187
|
-
end
|
188
|
-
|
189
|
-
# Processes through erb.
|
190
|
-
def erb(text)
|
191
|
-
erb = ERB.new(text)
|
192
|
-
erb.result(binding)
|
193
|
-
end
|
194
|
-
|
195
|
-
end#class Context
|
196
|
-
|
197
|
-
end#class Tiller
|
198
|
-
|
199
|
-
end
|
200
|
-
|