mack-markaby 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gems/markaby-0.5/lib/markaby/builder.rb +288 -0
- data/lib/gems/markaby-0.5/lib/markaby/cssproxy.rb +53 -0
- data/lib/gems/markaby-0.5/lib/markaby/metaid.rb +16 -0
- data/lib/gems/markaby-0.5/lib/markaby/rails.rb +46 -0
- data/lib/gems/markaby-0.5/lib/markaby/tags.rb +165 -0
- data/lib/gems/markaby-0.5/lib/markaby/template.rb +12 -0
- data/lib/gems/markaby-0.5/lib/markaby.rb +35 -0
- data/lib/gems.rb +13 -0
- data/lib/mack-markaby.rb +2 -0
- metadata +24 -16
@@ -0,0 +1,288 @@
|
|
1
|
+
require 'markaby/tags'
|
2
|
+
|
3
|
+
module Markaby
|
4
|
+
# The Markaby::Builder class is the central gear in the system. When using
|
5
|
+
# from Ruby code, this is the only class you need to instantiate directly.
|
6
|
+
#
|
7
|
+
# mab = Markaby::Builder.new
|
8
|
+
# mab.html do
|
9
|
+
# head { title "Boats.com" }
|
10
|
+
# body do
|
11
|
+
# h1 "Boats.com has great deals"
|
12
|
+
# ul do
|
13
|
+
# li "$49 for a canoe"
|
14
|
+
# li "$39 for a raft"
|
15
|
+
# li "$29 for a huge boot that floats and can fit 5 people"
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
# puts mab.to_s
|
20
|
+
#
|
21
|
+
class Builder
|
22
|
+
|
23
|
+
@@default = {
|
24
|
+
:indent => 0,
|
25
|
+
:output_helpers => true,
|
26
|
+
:output_xml_instruction => true,
|
27
|
+
:output_meta_tag => true,
|
28
|
+
:auto_validation => true,
|
29
|
+
:tagset => Markaby::XHTMLTransitional
|
30
|
+
}
|
31
|
+
|
32
|
+
def self.set(option, value)
|
33
|
+
@@default[option] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.ignored_helpers
|
37
|
+
@@ignored_helpers ||= []
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.ignore_helpers(*helpers)
|
41
|
+
ignored_helpers.concat helpers
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_accessor :output_helpers, :tagset
|
45
|
+
|
46
|
+
# Create a Markaby builder object. Pass in a hash of variable assignments to
|
47
|
+
# +assigns+ which will be available as instance variables inside tag construction
|
48
|
+
# blocks. If an object is passed in to +helpers+, its methods will be available
|
49
|
+
# from those same blocks.
|
50
|
+
#
|
51
|
+
# Pass in a +block+ to new and the block will be evaluated.
|
52
|
+
#
|
53
|
+
# mab = Markaby::Builder.new {
|
54
|
+
# html do
|
55
|
+
# body do
|
56
|
+
# h1 "Matching Mole"
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
# }
|
60
|
+
#
|
61
|
+
def initialize(assigns = {}, helpers = nil, &block)
|
62
|
+
@streams = [[]]
|
63
|
+
@assigns = assigns
|
64
|
+
@elements = {}
|
65
|
+
|
66
|
+
@@default.each do |k, v|
|
67
|
+
instance_variable_set("@#{k}", @assigns[k] || v)
|
68
|
+
end
|
69
|
+
|
70
|
+
if helpers.nil?
|
71
|
+
@helpers = nil
|
72
|
+
else
|
73
|
+
@helpers = helpers.dup
|
74
|
+
for iv in helpers.instance_variables
|
75
|
+
instance_variable_set(iv, helpers.instance_variable_get(iv))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
unless assigns.nil? || assigns.empty?
|
80
|
+
for iv, val in assigns
|
81
|
+
instance_variable_set("@#{iv}", val)
|
82
|
+
unless @helpers.nil?
|
83
|
+
@helpers.instance_variable_set("@#{iv}", val)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
@builder = ::Builder::XmlMarkup.new(:indent => @indent, :target => @streams.last)
|
89
|
+
class << @builder
|
90
|
+
attr_accessor :target, :level
|
91
|
+
end
|
92
|
+
|
93
|
+
if block
|
94
|
+
text(capture(&block))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns a string containing the HTML stream. Internally, the stream is stored as an Array.
|
99
|
+
def to_s
|
100
|
+
@streams.last.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
# Write a +string+ to the HTML stream without escaping it.
|
104
|
+
def text(string)
|
105
|
+
@builder << "#{string}"
|
106
|
+
nil
|
107
|
+
end
|
108
|
+
alias_method :<<, :text
|
109
|
+
alias_method :concat, :text
|
110
|
+
|
111
|
+
# Emulate ERB to satisfy helpers like <tt>form_for</tt>.
|
112
|
+
def _erbout; self end
|
113
|
+
|
114
|
+
# Captures the HTML code built inside the +block+. This is done by creating a new
|
115
|
+
# stream for the builder object, running the block and passing back its stream as a string.
|
116
|
+
#
|
117
|
+
# >> Markaby::Builder.new.capture { h1 "TEST"; h2 "CAPTURE ME" }
|
118
|
+
# => "<h1>TITLE</h1>\n<h2>CAPTURE ME</h2>\n"
|
119
|
+
#
|
120
|
+
def capture(&block)
|
121
|
+
@streams.push(builder.target = [])
|
122
|
+
@builder.level += 1
|
123
|
+
str = instance_eval(&block)
|
124
|
+
str = @streams.last.join if @streams.last.any?
|
125
|
+
@streams.pop
|
126
|
+
@builder.level -= 1
|
127
|
+
builder.target = @streams.last
|
128
|
+
str
|
129
|
+
end
|
130
|
+
|
131
|
+
# Create a tag named +tag+. Other than the first argument which is the tag name,
|
132
|
+
# the arguments are the same as the tags implemented via method_missing.
|
133
|
+
def tag!(tag, *args, &block)
|
134
|
+
ele_id = nil
|
135
|
+
if @auto_validation and @tagset
|
136
|
+
if !@tagset.tagset.has_key?(tag)
|
137
|
+
raise InvalidXhtmlError, "no element `#{tag}' for #{tagset.doctype}"
|
138
|
+
elsif args.last.respond_to?(:to_hash)
|
139
|
+
attrs = args.last.to_hash
|
140
|
+
attrs.each do |k, v|
|
141
|
+
atname = k.to_s.downcase.intern
|
142
|
+
unless k =~ /:/ or @tagset.tagset[tag].include? atname
|
143
|
+
raise InvalidXhtmlError, "no attribute `#{k}' on #{tag} elements"
|
144
|
+
end
|
145
|
+
if atname == :id
|
146
|
+
ele_id = v.to_s
|
147
|
+
if @elements.has_key? ele_id
|
148
|
+
raise InvalidXhtmlError, "id `#{ele_id}' already used (id's must be unique)."
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
if block
|
155
|
+
str = capture &block
|
156
|
+
block = proc { text(str) }
|
157
|
+
end
|
158
|
+
|
159
|
+
f = fragment { @builder.method_missing(tag, *args, &block) }
|
160
|
+
@elements[ele_id] = f if ele_id
|
161
|
+
f
|
162
|
+
end
|
163
|
+
|
164
|
+
# This method is used to intercept calls to helper methods and instance
|
165
|
+
# variables. Here is the order of interception:
|
166
|
+
#
|
167
|
+
# * If +sym+ is a helper method, the helper method is called
|
168
|
+
# and output to the stream.
|
169
|
+
# * If +sym+ is a Builder::XmlMarkup method, it is passed on to the builder object.
|
170
|
+
# * If +sym+ is also the name of an instance variable, the
|
171
|
+
# value of the instance variable is returned.
|
172
|
+
# * If +sym+ has come this far and no +tagset+ is found, +sym+ and its arguments are passed to tag!
|
173
|
+
# * If a tagset is found, though, +NoMethodError+ is raised.
|
174
|
+
#
|
175
|
+
# method_missing used to be the lynchpin in Markaby, but it's no longer used to handle
|
176
|
+
# HTML tags. See html_tag for that.
|
177
|
+
def method_missing(sym, *args, &block)
|
178
|
+
if @helpers.respond_to?(sym, true) && !self.class.ignored_helpers.include?(sym)
|
179
|
+
r = @helpers.send(sym, *args, &block)
|
180
|
+
if @output_helpers and r.respond_to? :to_str
|
181
|
+
fragment { @builder << r }
|
182
|
+
else
|
183
|
+
r
|
184
|
+
end
|
185
|
+
elsif ::Builder::XmlMarkup.instance_methods.include?(sym.to_s)
|
186
|
+
@builder.__send__(sym, *args, &block)
|
187
|
+
elsif instance_variables.include?("@#{sym}")
|
188
|
+
instance_variable_get("@#{sym}")
|
189
|
+
elsif @tagset.nil?
|
190
|
+
tag!(sym, *args, &block)
|
191
|
+
else
|
192
|
+
raise NoMethodError, "no such method `#{sym}'"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Every HTML tag method goes through an html_tag call. So, calling <tt>div</tt> is equivalent
|
197
|
+
# to calling <tt>html_tag(:div)</tt>. All HTML tags in Markaby's list are given generated wrappers
|
198
|
+
# for this method.
|
199
|
+
#
|
200
|
+
# If the @auto_validation setting is on, this method will check for many common mistakes which
|
201
|
+
# could lead to invalid XHTML.
|
202
|
+
def html_tag(sym, *args, &block)
|
203
|
+
if @auto_validation and @tagset.self_closing.include?(sym) and block
|
204
|
+
raise InvalidXhtmlError, "the `\#{sym}' element is self-closing, please remove the block"
|
205
|
+
end
|
206
|
+
if args.empty? and block.nil? and not NO_PROXY.include?(sym)
|
207
|
+
return CssProxy.new do |args, block|
|
208
|
+
if @tagset.forms.include?(sym) and args.last.respond_to?(:to_hash) and args.last[:id]
|
209
|
+
args.last[:name] ||= args.last[:id]
|
210
|
+
end
|
211
|
+
tag!(sym, *args, &block)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
if not @tagset.self_closing.include?(sym) and args.first.respond_to?(:to_hash)
|
215
|
+
block ||= proc{}
|
216
|
+
end
|
217
|
+
tag!(sym, *args, &block)
|
218
|
+
end
|
219
|
+
|
220
|
+
XHTMLTransitional.tags.each do |k|
|
221
|
+
class_eval %{
|
222
|
+
def #{k}(*args, &block)
|
223
|
+
html_tag(#{k.inspect}, *args, &block)
|
224
|
+
end
|
225
|
+
}
|
226
|
+
end
|
227
|
+
|
228
|
+
# Builds a head tag. Adds a <tt>meta</tt> tag inside with Content-Type
|
229
|
+
# set to <tt>text/html; charset=utf-8</tt>.
|
230
|
+
def head(*args, &block)
|
231
|
+
tag!(:head, *args) do
|
232
|
+
tag!(:meta, "http-equiv" => "Content-Type", "content" => "text/html; charset=utf-8") if @output_meta_tag
|
233
|
+
instance_eval(&block)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# Builds an html tag. An XML 1.0 instruction and an XHTML 1.0 Transitional doctype
|
238
|
+
# are prepended. Also assumes <tt>:xmlns => "http://www.w3.org/1999/xhtml",
|
239
|
+
# :lang => "en"</tt>.
|
240
|
+
def xhtml_transitional(&block)
|
241
|
+
self.tagset = Markaby::XHTMLTransitional
|
242
|
+
xhtml_html &block
|
243
|
+
end
|
244
|
+
|
245
|
+
# Builds an html tag with XHTML 1.0 Strict doctype instead.
|
246
|
+
def xhtml_strict(&block)
|
247
|
+
self.tagset = Markaby::XHTMLStrict
|
248
|
+
xhtml_html &block
|
249
|
+
end
|
250
|
+
|
251
|
+
private
|
252
|
+
|
253
|
+
def xhtml_html(&block)
|
254
|
+
instruct! if @output_xml_instruction
|
255
|
+
declare!(:DOCTYPE, :html, :PUBLIC, *tagset.doctype)
|
256
|
+
tag!(:html, :xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en", &block)
|
257
|
+
end
|
258
|
+
|
259
|
+
def fragment
|
260
|
+
stream = @streams.last
|
261
|
+
f1 = stream.length
|
262
|
+
yield
|
263
|
+
f2 = stream.length - f1
|
264
|
+
Fragment.new(stream, f1, f2)
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
# Every tag method in Markaby returns a Fragment. If any method gets called on the Fragment,
|
270
|
+
# the tag is removed from the Markaby stream and given back as a string. Usually the fragment
|
271
|
+
# is never used, though, and the stream stays intact.
|
272
|
+
#
|
273
|
+
# For a more practical explanation, check out the README.
|
274
|
+
class Fragment < ::Builder::BlankSlate
|
275
|
+
def initialize(s, a, b)
|
276
|
+
@s, @f1, @f2 = s, a, b
|
277
|
+
end
|
278
|
+
def method_missing(*a)
|
279
|
+
unless @str
|
280
|
+
@str = @s[@f1, @f2].to_s
|
281
|
+
@s[@f1, @f2] = [nil] * @f2
|
282
|
+
@str
|
283
|
+
end
|
284
|
+
@str.send(*a)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Markaby
|
2
|
+
# Class used by Markaby::Builder to store element options. Methods called
|
3
|
+
# against the CssProxy object are added as element classes or IDs.
|
4
|
+
#
|
5
|
+
# See the README for examples.
|
6
|
+
class CssProxy
|
7
|
+
|
8
|
+
# Creates a CssProxy object. The +opts+ and +block+ passed in are
|
9
|
+
# stored until the element is created by Builder.tag!
|
10
|
+
def initialize(opts = {}, &blk)
|
11
|
+
@opts = opts
|
12
|
+
@blk = blk
|
13
|
+
end
|
14
|
+
|
15
|
+
# Adds attributes to an element, for internal use only. For example, if you
|
16
|
+
# want to write a wrapper which sets a bunch of default attributes for a certain
|
17
|
+
# tag. Like the default `img' method included with Markaby automatically sets an
|
18
|
+
# empty alt attribute.
|
19
|
+
def merge!(opts)
|
20
|
+
@opts.merge! opts
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
# Adds attributes to an element. Bang methods set the :id attribute.
|
25
|
+
# Other methods add to the :class attribute. If a block is supplied,
|
26
|
+
# it is executed with a merged hash (@opts + args).
|
27
|
+
def method_missing(id_or_class, *args, &blk)
|
28
|
+
idc = id_or_class.to_s
|
29
|
+
case idc
|
30
|
+
when "pass"
|
31
|
+
when /!$/
|
32
|
+
@opts[:id] = $`
|
33
|
+
else
|
34
|
+
@opts[:class] = "#{@opts[:class]} #{idc}".strip
|
35
|
+
end
|
36
|
+
if args.empty? and blk.nil?
|
37
|
+
self
|
38
|
+
else
|
39
|
+
if args.last.respond_to? :to_hash
|
40
|
+
@opts.merge!(args.pop.to_hash)
|
41
|
+
end
|
42
|
+
args.push @opts
|
43
|
+
@blk.call(args, blk)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_str
|
48
|
+
@blk.call([[@opts]]).to_s
|
49
|
+
end
|
50
|
+
alias_method :to_s, :to_str
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# metaprogramming assistant -- metaid.rb
|
2
|
+
class Object
|
3
|
+
# The hidden singleton lurks behind everyone
|
4
|
+
def metaclass; class << self; self; end; end
|
5
|
+
def meta_eval &blk; metaclass.instance_eval &blk; end
|
6
|
+
|
7
|
+
# Adds methods to a metaclass
|
8
|
+
def meta_def name, &blk
|
9
|
+
meta_eval { define_method name, &blk }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Defines an instance method within a class
|
13
|
+
def class_def name, &blk
|
14
|
+
class_eval { define_method name, &blk }
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Markaby
|
2
|
+
|
3
|
+
# Markaby helpers for Rails.
|
4
|
+
module ActionControllerHelpers
|
5
|
+
# Returns a string of HTML built from the attached +block+. Any +options+ are
|
6
|
+
# passed into the render method.
|
7
|
+
#
|
8
|
+
# Use this method in your controllers to output Markaby directly from inside.
|
9
|
+
def render_markaby(options = {}, &block)
|
10
|
+
render options.merge({ :text => Builder.new({}, self, &block).to_s })
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ActionViewTemplateHandler
|
15
|
+
def initialize(action_view)
|
16
|
+
@action_view = action_view
|
17
|
+
end
|
18
|
+
def render(template, local_assigns = {})
|
19
|
+
Template.new(template).render(@action_view.assigns.merge(local_assigns), @action_view)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Builder
|
24
|
+
# Emulate ERB to satisfy helpers like <tt>form_for</tt>.
|
25
|
+
def _erbout; self end
|
26
|
+
|
27
|
+
# Content_for will store the given block in an instance variable for later use
|
28
|
+
# in another template or in the layout.
|
29
|
+
#
|
30
|
+
# The name of the instance variable is content_for_<name> to stay consistent
|
31
|
+
# with @content_for_layout which is used by ActionView's layouts.
|
32
|
+
#
|
33
|
+
# Example:
|
34
|
+
#
|
35
|
+
# content_for("header") do
|
36
|
+
# h1 "Half Shark and Half Lion"
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# If used several times, the variable will contain all the parts concatenated.
|
40
|
+
def content_for(name, &block)
|
41
|
+
@helpers.assigns["content_for_#{name}"] =
|
42
|
+
eval("@content_for_#{name} = (@content_for_#{name} || '') + capture(&block)")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
module Markaby
|
2
|
+
|
3
|
+
FORM_TAGS = [ :form, :input, :select, :textarea ]
|
4
|
+
SELF_CLOSING_TAGS = [ :base, :meta, :link, :hr, :br, :param, :img, :area, :input, :col ]
|
5
|
+
NO_PROXY = [ :hr, :br ]
|
6
|
+
|
7
|
+
# Common sets of attributes.
|
8
|
+
AttrCore = [:id, :class, :style, :title]
|
9
|
+
AttrI18n = [:lang, 'xml:lang'.intern, :dir]
|
10
|
+
AttrEvents = [:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover, :onmousemove,
|
11
|
+
:onmouseout, :onkeypress, :onkeydown, :onkeyup]
|
12
|
+
AttrFocus = [:accesskey, :tabindex, :onfocus, :onblur]
|
13
|
+
AttrHAlign = [:align, :char, :charoff]
|
14
|
+
AttrVAlign = [:valign]
|
15
|
+
Attrs = AttrCore + AttrI18n + AttrEvents
|
16
|
+
|
17
|
+
# All the tags and attributes from XHTML 1.0 Strict
|
18
|
+
class XHTMLStrict
|
19
|
+
class << self
|
20
|
+
attr_accessor :tags, :tagset, :forms, :self_closing, :doctype
|
21
|
+
end
|
22
|
+
@doctype = ["-//W3C//DTD XHTML 1.0 Strict//EN", "DTD/xhtml1-strict.dtd"]
|
23
|
+
@tagset = {
|
24
|
+
:html => AttrI18n + [:id, :xmlns],
|
25
|
+
:head => AttrI18n + [:id, :profile],
|
26
|
+
:title => AttrI18n + [:id],
|
27
|
+
:base => [:href, :id],
|
28
|
+
:meta => AttrI18n + [:id, :http, :name, :content, :scheme, 'http-equiv'.intern],
|
29
|
+
:link => Attrs + [:charset, :href, :hreflang, :type, :rel, :rev, :media],
|
30
|
+
:style => AttrI18n + [:id, :type, :media, :title, 'xml:space'.intern],
|
31
|
+
:script => [:id, :charset, :type, :src, :defer, 'xml:space'.intern],
|
32
|
+
:noscript => Attrs,
|
33
|
+
:body => Attrs + [:onload, :onunload],
|
34
|
+
:div => Attrs,
|
35
|
+
:p => Attrs,
|
36
|
+
:ul => Attrs,
|
37
|
+
:ol => Attrs,
|
38
|
+
:li => Attrs,
|
39
|
+
:dl => Attrs,
|
40
|
+
:dt => Attrs,
|
41
|
+
:dd => Attrs,
|
42
|
+
:address => Attrs,
|
43
|
+
:hr => Attrs,
|
44
|
+
:pre => Attrs + ['xml:space'.intern],
|
45
|
+
:blockquote => Attrs + [:cite],
|
46
|
+
:ins => Attrs + [:cite, :datetime],
|
47
|
+
:del => Attrs + [:cite, :datetime],
|
48
|
+
:a => Attrs + AttrFocus + [:charset, :type, :name, :href, :hreflang, :rel, :rev, :shape, :coords],
|
49
|
+
:span => Attrs,
|
50
|
+
:bdo => AttrCore + AttrEvents + [:lang, 'xml:lang'.intern, :dir],
|
51
|
+
:br => AttrCore,
|
52
|
+
:em => Attrs,
|
53
|
+
:strong => Attrs,
|
54
|
+
:dfn => Attrs,
|
55
|
+
:code => Attrs,
|
56
|
+
:samp => Attrs,
|
57
|
+
:kbd => Attrs,
|
58
|
+
:var => Attrs,
|
59
|
+
:cite => Attrs,
|
60
|
+
:abbr => Attrs,
|
61
|
+
:acronym => Attrs,
|
62
|
+
:q => Attrs + [:cite],
|
63
|
+
:sub => Attrs,
|
64
|
+
:sup => Attrs,
|
65
|
+
:tt => Attrs,
|
66
|
+
:i => Attrs,
|
67
|
+
:b => Attrs,
|
68
|
+
:big => Attrs,
|
69
|
+
:small => Attrs,
|
70
|
+
:object => Attrs + [:declare, :classid, :codebase, :data, :type, :codetype, :archive, :standby, :height, :width, :usemap, :name, :tabindex],
|
71
|
+
:param => [:id, :name, :value, :valuetype, :type],
|
72
|
+
:img => Attrs + [:src, :alt, :longdesc, :height, :width, :usemap, :ismap],
|
73
|
+
:map => AttrI18n + AttrEvents + [:id, :class, :style, :title, :name],
|
74
|
+
:area => Attrs + AttrFocus + [:shape, :coords, :href, :nohref, :alt],
|
75
|
+
:form => Attrs + [:action, :method, :enctype, :onsubmit, :onreset, :accept, :accept],
|
76
|
+
:label => Attrs + [:for, :accesskey, :onfocus, :onblur],
|
77
|
+
:input => Attrs + AttrFocus + [:type, :name, :value, :checked, :disabled, :readonly, :size, :maxlength, :src, :alt, :usemap, :onselect, :onchange, :accept],
|
78
|
+
:select => Attrs + [:name, :size, :multiple, :disabled, :tabindex, :onfocus, :onblur, :onchange],
|
79
|
+
:optgroup => Attrs + [:disabled, :label],
|
80
|
+
:option => Attrs + [:selected, :disabled, :label, :value],
|
81
|
+
:textarea => Attrs + AttrFocus + [:name, :rows, :cols, :disabled, :readonly, :onselect, :onchange],
|
82
|
+
:fieldset => Attrs,
|
83
|
+
:legend => Attrs + [:accesskey],
|
84
|
+
:button => Attrs + AttrFocus + [:name, :value, :type, :disabled],
|
85
|
+
:table => Attrs + [:summary, :width, :border, :frame, :rules, :cellspacing, :cellpadding],
|
86
|
+
:caption => Attrs,
|
87
|
+
:colgroup => Attrs + AttrHAlign + AttrVAlign + [:span, :width],
|
88
|
+
:col => Attrs + AttrHAlign + AttrVAlign + [:span, :width],
|
89
|
+
:thead => Attrs + AttrHAlign + AttrVAlign,
|
90
|
+
:tfoot => Attrs + AttrHAlign + AttrVAlign,
|
91
|
+
:tbody => Attrs + AttrHAlign + AttrVAlign,
|
92
|
+
:tr => Attrs + AttrHAlign + AttrVAlign,
|
93
|
+
:th => Attrs + AttrHAlign + AttrVAlign + [:abbr, :axis, :headers, :scope, :rowspan, :colspan],
|
94
|
+
:td => Attrs + AttrHAlign + AttrVAlign + [:abbr, :axis, :headers, :scope, :rowspan, :colspan],
|
95
|
+
:h1 => Attrs,
|
96
|
+
:h2 => Attrs,
|
97
|
+
:h3 => Attrs,
|
98
|
+
:h4 => Attrs,
|
99
|
+
:h5 => Attrs,
|
100
|
+
:h6 => Attrs
|
101
|
+
}
|
102
|
+
|
103
|
+
@tags = @tagset.keys
|
104
|
+
@forms = @tags & FORM_TAGS
|
105
|
+
@self_closing = @tags & SELF_CLOSING_TAGS
|
106
|
+
end
|
107
|
+
|
108
|
+
# Additional tags found in XHTML 1.0 Transitional
|
109
|
+
class XHTMLTransitional
|
110
|
+
class << self
|
111
|
+
attr_accessor :tags, :tagset, :forms, :self_closing, :doctype
|
112
|
+
end
|
113
|
+
@doctype = ["-//W3C//DTD XHTML 1.0 Transitional//EN", "DTD/xhtml1-transitional.dtd"]
|
114
|
+
@tagset = XHTMLStrict.tagset.merge \
|
115
|
+
:strike => Attrs,
|
116
|
+
:center => Attrs,
|
117
|
+
:dir => Attrs + [:compact],
|
118
|
+
:noframes => Attrs,
|
119
|
+
:basefont => [:id, :size, :color, :face],
|
120
|
+
:u => Attrs,
|
121
|
+
:menu => Attrs + [:compact],
|
122
|
+
:iframe => AttrCore + [:longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :scrolling, :align, :height, :width],
|
123
|
+
:font => AttrCore + AttrI18n + [:size, :color, :face],
|
124
|
+
:s => Attrs,
|
125
|
+
:applet => AttrCore + [:codebase, :archive, :code, :object, :alt, :name, :width, :height, :align, :hspace, :vspace],
|
126
|
+
:isindex => AttrCore + AttrI18n + [:prompt]
|
127
|
+
|
128
|
+
# Additional attributes found in XHTML 1.0 Transitional
|
129
|
+
{ :script => [:language],
|
130
|
+
:a => [:target],
|
131
|
+
:td => [:bgcolor, :nowrap, :width, :height],
|
132
|
+
:p => [:align],
|
133
|
+
:h5 => [:align],
|
134
|
+
:h3 => [:align],
|
135
|
+
:li => [:type, :value],
|
136
|
+
:div => [:align],
|
137
|
+
:pre => [:width],
|
138
|
+
:body => [:background, :bgcolor, :text, :link, :vlink, :alink],
|
139
|
+
:ol => [:type, :compact, :start],
|
140
|
+
:h4 => [:align],
|
141
|
+
:h2 => [:align],
|
142
|
+
:object => [:align, :border, :hspace, :vspace],
|
143
|
+
:img => [:name, :align, :border, :hspace, :vspace],
|
144
|
+
:link => [:target],
|
145
|
+
:legend => [:align],
|
146
|
+
:dl => [:compact],
|
147
|
+
:input => [:align],
|
148
|
+
:h6 => [:align],
|
149
|
+
:hr => [:align, :noshade, :size, :width],
|
150
|
+
:base => [:target],
|
151
|
+
:ul => [:type, :compact],
|
152
|
+
:br => [:clear],
|
153
|
+
:form => [:name, :target],
|
154
|
+
:area => [:target],
|
155
|
+
:h1 => [:align]
|
156
|
+
}.each do |k, v|
|
157
|
+
@tagset[k] += v
|
158
|
+
end
|
159
|
+
|
160
|
+
@tags = @tagset.keys
|
161
|
+
@forms = @tags & FORM_TAGS
|
162
|
+
@self_closing = @tags & SELF_CLOSING_TAGS
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# = About lib/markaby.rb
|
2
|
+
#
|
3
|
+
# By requiring <tt>lib/markaby</tt>, you can load Markaby's dependency (the Builder library,)
|
4
|
+
# as well as the full set of Markaby classes.
|
5
|
+
#
|
6
|
+
# For a full list of features and instructions, see the README.
|
7
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
8
|
+
|
9
|
+
# Markaby is a module containing all of the great Markaby classes that
|
10
|
+
# do such an excellent job.
|
11
|
+
#
|
12
|
+
# * Markaby::Builder: the class for actually calling the Ruby methods
|
13
|
+
# which write the HTML.
|
14
|
+
# * Markaby::CSSProxy: a class which adds element classes and IDs to
|
15
|
+
# elements when used within Markaby::Builder.
|
16
|
+
# * Markaby::MetAid: metaprogramming helper methods.
|
17
|
+
# * Markaby::Tags: lists the roles of various XHTML tags to help Builder
|
18
|
+
# use these tags as they are intended.
|
19
|
+
# * Markaby::Template: a class for hooking Markaby into Rails as a
|
20
|
+
# proper templating language.
|
21
|
+
module Markaby
|
22
|
+
VERSION = '0.5'
|
23
|
+
|
24
|
+
class InvalidXhtmlError < Exception; end
|
25
|
+
end
|
26
|
+
|
27
|
+
unless defined?(Builder)
|
28
|
+
require 'rubygems'
|
29
|
+
require 'builder'
|
30
|
+
end
|
31
|
+
|
32
|
+
require 'markaby/builder'
|
33
|
+
require 'markaby/cssproxy'
|
34
|
+
require 'markaby/metaid'
|
35
|
+
require 'markaby/template'
|
data/lib/gems.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), 'gems'))
|
2
|
+
Gem.set_paths(path)
|
3
|
+
|
4
|
+
Dir.glob(File.join(path, '*')).each do |p|
|
5
|
+
full_gem_name = File.basename(p)
|
6
|
+
version = full_gem_name.match(/([\d\.?]+)/).to_s
|
7
|
+
gem_name = full_gem_name.gsub("-#{version}", '')
|
8
|
+
$:.unshift(File.join(p, 'lib'))
|
9
|
+
begin
|
10
|
+
gem gem_name, "~> #{version}"
|
11
|
+
rescue Gem::LoadError
|
12
|
+
end
|
13
|
+
end
|
data/lib/mack-markaby.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mack-markaby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darsono Sutedja
|
@@ -9,19 +9,10 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-30 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: markaby
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - "="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.5.0
|
24
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
25
16
|
description: Markaby Rendering Engine for Mack Framework
|
26
17
|
email: darsono.sutedja@gmail.com
|
27
18
|
executables: []
|
@@ -31,14 +22,31 @@ extensions: []
|
|
31
22
|
extra_rdoc_files: []
|
32
23
|
|
33
24
|
files:
|
25
|
+
- lib/gems
|
26
|
+
- lib/gems/cache
|
27
|
+
- lib/gems/doc
|
28
|
+
- lib/gems/gems
|
29
|
+
- lib/gems/markaby-0.5
|
30
|
+
- lib/gems/markaby-0.5/lib
|
31
|
+
- lib/gems/markaby-0.5/lib/markaby
|
32
|
+
- lib/gems/markaby-0.5/lib/markaby/builder.rb
|
33
|
+
- lib/gems/markaby-0.5/lib/markaby/cssproxy.rb
|
34
|
+
- lib/gems/markaby-0.5/lib/markaby/metaid.rb
|
35
|
+
- lib/gems/markaby-0.5/lib/markaby/rails.rb
|
36
|
+
- lib/gems/markaby-0.5/lib/markaby/tags.rb
|
37
|
+
- lib/gems/markaby-0.5/lib/markaby/template.rb
|
38
|
+
- lib/gems/markaby-0.5/lib/markaby.rb
|
39
|
+
- lib/gems/specifications
|
40
|
+
- lib/gems.rb
|
41
|
+
- lib/mack-markaby
|
34
42
|
- lib/mack-markaby/markaby_engine.rb
|
35
43
|
- lib/mack-markaby.rb
|
36
44
|
- README
|
37
45
|
has_rdoc: true
|
38
46
|
homepage: http://www.mackframework.com
|
39
47
|
post_install_message:
|
40
|
-
rdoc_options:
|
41
|
-
|
48
|
+
rdoc_options:
|
49
|
+
- --exclude=gems/
|
42
50
|
require_paths:
|
43
51
|
- lib
|
44
52
|
- lib
|
@@ -57,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
65
|
requirements: []
|
58
66
|
|
59
67
|
rubyforge_project: magrathea
|
60
|
-
rubygems_version: 1.
|
68
|
+
rubygems_version: 1.3.1
|
61
69
|
signing_key:
|
62
70
|
specification_version: 2
|
63
71
|
summary: Rendering Engine
|