Changeset 83
- Timestamp:
- 10/16/2006 13:39:00 (2 years ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
Rakefile (modified) (1 diff)
-
lib/markaby/builder.rb (modified) (8 diffs)
-
lib/markaby/metaid.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Rakefile
r80 r83 19 19 test_file = "test/test_markaby.rb" 20 20 setup_gem("markaby", VERS, "Tim Fletcher and _why", summary, [['builder', '>=2.0.0']], test_file) 21 22 desc "List any Markaby specific warnings" 23 task :warnings do 24 `ruby -w test/test_markaby.rb 2>&1`.split(/\n/).each do |line| 25 next unless line =~ /warning:/ 26 next if line =~ /builder-/ 27 puts line 28 end 29 end -
trunk/lib/markaby/builder.rb
r80 r83 88 88 @builder = ::Builder::XmlMarkup.new(:indent => @indent, :target => @streams.last) 89 89 class << @builder 90 attr_accessor :target, :level 91 end 92 93 if block 94 text(capture(&block)) 95 end 90 attr_accessor :target, :level 91 end 92 93 text(capture(&block)) if block 96 94 end 97 95 … … 153 151 end 154 152 if block 155 str = capture &block153 str = capture(&block) 156 154 block = proc { text(str) } 157 155 end … … 212 210 end 213 211 end 214 if not @tagset.self_closing.include?(sym) and args.first.respond_to?(:to_hash)215 block ||= proc{}216 end217 212 tag!(sym, *args, &block) 218 213 end … … 226 221 end 227 222 223 remove_method :head 224 228 225 # Builds a head tag. Adds a <tt>meta</tt> tag inside with Content-Type 229 226 # set to <tt>text/html; charset=utf-8</tt>. … … 240 237 def xhtml_transitional(&block) 241 238 self.tagset = Markaby::XHTMLTransitional 242 xhtml_html &block239 xhtml_html(&block) 243 240 end 244 241 … … 246 243 def xhtml_strict(&block) 247 244 self.tagset = Markaby::XHTMLStrict 248 xhtml_html &block245 xhtml_html(&block) 249 246 end 250 247 … … 259 256 def fragment 260 257 stream = @streams.last 261 f1= stream.length258 start = stream.length 262 259 yield 263 f2 = stream.length - f1264 Fragment.new(stream, f1, f2)260 length = stream.length - start 261 Fragment.new(stream, start, length) 265 262 end 266 263 … … 273 270 # For a more practical explanation, check out the README. 274 271 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) 272 def initialize(*args) 273 @stream, @start, @length = args 274 end 275 def method_missing(*args) 276 # We can't do @stream.slice!(@start, @length), 277 # as it would invalidate the @starts and @lengths of other Fragment instances. 278 @str = @stream[@start, @length].to_s 279 @stream[@start, @length] = [nil] * @length 280 def self.method_missing(*args, &block) 281 @str.send(*args, &block) 282 end 283 @str.send(*args, &block) 285 284 end 286 285 end -
trunk/lib/markaby/metaid.rb
r1 r83 1 1 # metaprogramming assistant -- metaid.rb 2 class Object 2 class Object # :nodoc: 3 3 # The hidden singleton lurks behind everyone 4 4 def metaclass; class << self; self; end; end 5 def meta_eval &blk; metaclass.instance_eval &blk; end5 def meta_eval(&blk); metaclass.instance_eval(&blk); end 6 6 7 7 # Adds methods to a metaclass 8 def meta_def name, &blk9 meta_eval { define_method name, &blk}8 def meta_def(name, &blk) 9 meta_eval { define_method(name, &blk) } 10 10 end 11 11 12 12 # Defines an instance method within a class 13 def class_def name, &blk14 class_eval { define_method name, &blk}13 def class_def(name, &blk) 14 class_eval { define_method(name, &blk) } 15 15 end 16 16 end