Class: Builder::XmlMarkup
Defined Under Namespace
Classes: AbortTransaction
Class Attribute Summary collapse
Instance Method Summary
collapse
Class Attribute Details
.environment ⇒ Object
Returns the value of attribute environment.
32
33
34
|
# File 'lib/smklib/builder_ext.rb', line 32
def environment
@environment
end
|
Instance Method Details
25
26
27
|
# File 'lib/smklib/builder_ext.rb', line 25
def abort!
raise AbortTransaction, "abort" unless @ignore_abort
end
|
#get_img_size(filename) ⇒ Object
69
70
71
72
|
# File 'lib/smklib/builder_ext.rb', line 69
def get_img_size(filename)
im = Magick::Image.read(real_filename(filename)).first
return [im.columns, im.rows]
end
|
35
36
37
38
39
|
# File 'lib/smklib/builder_ext.rb', line 35
def get_ua
env = ENV
env = Builder::XmlMarkup.environment if Builder::XmlMarkup.environment
env['HTTP_USER_AGENT']
end
|
#ignore_abort!(val = true) ⇒ Object
21
22
23
|
# File 'lib/smklib/builder_ext.rb', line 21
def ignore_abort!(val = true)
@ignore_abort = val
end
|
#img(options = {}) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/smklib/builder_ext.rb', line 74
def img(options = {})
if get_ua =~ /MSIE 6.*Windows/
if options[:src] =~ /\.png$/
options[:style] = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{options[:src]}', sizingMethod='scale');" + options[:style].to_s
options[:width], options[:height] = get_img_size(options[:src]) unless options[:width] && options[:height]
options[:src] = '/images/spacer.gif'
end
end
if block_given?
method_missing(:img, options, yield)
else
method_missing(:img, options)
end
end
|
#nbsp(count = 1) ⇒ Object
89
90
91
|
# File 'lib/smklib/builder_ext.rb', line 89
def nbsp(count=1)
self << (1..count).collect{ " " }.join
end
|
#ob2(ob, *extra, &block) ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'lib/smklib/builder_ext.rb', line 93
def ob2(ob, *, &block)
ob = Class.const_get('OdlumBox2').new(ob) if ob.kind_of? Hash
div(*) do
ob.render(self) { |xml|
yield
}
end
end
|
#real_filename(filename) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/smklib/builder_ext.rb', line 61
def real_filename(filename)
if defined?(RAILS_ROOT)
RAILS_ROOT + "/public/" + filename
else
filename
end
end
|
#sortable_column_header(label, link, options = {}) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/smklib/builder_ext.rb', line 50
def sortable_column_header(label, link, options = {})
th(options) do
if !label.empty?
a("href" => link) { self << " #{label} " }
else
self << " "
end
end
end
|
#table_row(cells, tr_options = {}, td_options = {}) ⇒ Object
cells is an array of objects that respond to to_s
46
47
48
|
# File 'lib/smklib/builder_ext.rb', line 46
def table_row(cells, tr_options = {}, td_options = {})
tr(tr_options) { cells.each_with_index { |i,k| td(td_options[k] || {}) { self << i.to_s } } }
end
|
#tight_table(options = {}) ⇒ Object
41
42
43
|
# File 'lib/smklib/builder_ext.rb', line 41
def tight_table(options = {})
table({ "cellspacing" => 0, "cellpadding" => 0, "border" => 0 }.merge(options)) { yield }
end
|
#transaction!(&block) ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/smklib/builder_ext.rb', line 10
def transaction!(&block)
old_target = @target
@target = ''
begin
yield
@target = old_target + @target
rescue AbortTransaction => e
@target = old_target
end
end
|