| Class | RSS::XMLStyleSheet |
| In: |
lib/rss/xml-stylesheet.rb
|
| Parent: | Object |
| ATTRIBUTES | = | %w(href type title media charset alternate) |
| GUESS_TABLE | = | { "xsl" => "text/xsl", "css" => "text/css", } |
| do_validate | [RW] |
# File lib/rss/xml-stylesheet.rb, line 37
37: def initialize(*attrs)
38: if attrs.size == 1 and
39: (attrs.first.is_a?(Hash) or attrs.first.is_a?(Array))
40: attrs = attrs.first
41: end
42: @do_validate = true
43: ATTRIBUTES.each do |attr|
44: __send__("#{attr}=", nil)
45: end
46: vars = ATTRIBUTES.dup
47: vars.unshift(:do_validate)
48: attrs.each do |name, value|
49: if vars.include?(name.to_s)
50: __send__("#{name}=", value)
51: end
52: end
53: end
# File lib/rss/xml-stylesheet.rb, line 79
79: def alternate=(value)
80: if value.nil? or /\A(?:yes|no)\z/ =~ value
81: @alternate = value
82: else
83: if @do_validate
84: args = ["?xml-stylesheet?", %Q[alternate="#{value}"]]
85: raise NotAvailableValueError.new(*args)
86: end
87: end
88: @alternate
89: end
# File lib/rss/xml-stylesheet.rb, line 70
70: def href=(value)
71: @href = value
72: if @href and @type.nil?
73: @type = guess_type(@href)
74: end
75: @href
76: end
# File lib/rss/xml-stylesheet.rb, line 91
91: def setup_maker(maker)
92: xss = maker.xml_stylesheets.new_xml_stylesheet
93: ATTRIBUTES.each do |attr|
94: xss.__send__("#{attr}=", __send__(attr))
95: end
96: end
# File lib/rss/xml-stylesheet.rb, line 55
55: def to_s
56: rv = ""
57: if @href
58: rv << %Q[<?xml-stylesheet]
59: ATTRIBUTES.each do |name|
60: if __send__(name)
61: rv << %Q[ #{name}="#{h __send__(name)}"]
62: end
63: end
64: rv << %Q[?>]
65: end
66: rv
67: end