Class | Hobix::BaseContent |
In: |
lib/hobix/base.rb
|
Parent: | Object |
to_yaml | -> | to_yaml_orig |
Load the weblog entry from a file.
# File lib/hobix/base.rb, line 410 410: def self.load( file ) 411: File.open( file ) { |f| YAML::load( f ) } 412: end
Factory method for generating Entry classes from a hash. Used by the YAML loader.
# File lib/hobix/base.rb, line 425 425: def self.maker( val ) 426: self::text_processor_fields.each do |f| 427: if val[f].respond_to? :value 428: str = val[f].value 429: def str.to_html 430: self 431: end 432: val[f] = str 433: elsif val[f].respond_to? :to_str 434: val[f] = self::text_processor.new( val[f].to_str ) 435: end 436: end 437: YAML::object_maker( self, val ) 438: end
# File lib/hobix/base.rb, line 327 327: def self.no_implicit_tags 328: @@no_implicit_tags = true 329: end
# File lib/hobix/base.rb, line 347 347: def self.split_implicit_tags 348: @@split_implicit_tags = true 349: end
Returns an Array of fields to which the text processor applies.
# File lib/hobix/base.rb, line 418 418: def self.text_processor_fields 419: self.properties.map do |name, opts| 420: name.to_s if opts and opts[:text_processor] 421: end.compact 422: end
# File lib/hobix/base.rb, line 318 318: def self.url_link( e, url = nil, ext = nil ); "#{ url }/#{ link_format e }#{ '.' + ext if ext }"; end
# File lib/hobix/base.rb, line 380 380: def self.yaml_type( tag ) 381: # if self.respond_to? :yaml_as 382: # yaml_as tag 383: # else 384: if tag =~ /^tag:([^:]+):(.+)$/ 385: define_method( :to_yaml_type ) { "!#$1/#$2" } 386: YAML::add_domain_type( $1, $2 ) { |t, v| self.maker( v ) } 387: end 388: # end 389: end
return an array of tags deduced from the path i.e. a path like ruby/hobix/foo.yml will lead to [ ruby, hobix ] tags Occurence of . (alone) will be either removed or replaced by the value of root_tag
# File lib/hobix/base.rb, line 358 358: def path_to_tags( path ) 359: return [] if @@no_implicit_tags 360: return [] if path.nil? 361: if @@split_implicit_tags 362: tags_array = path.split("/").find_all { |e| e.size > 0 } 363: tags_array.pop # Last item is the entry title 364: else 365: tags_array = [ File.dirname( path )] 366: end 367: tags_array.map { |e| e == '.' ? @@root_tag : e }.compact 368: end
# File lib/hobix/base.rb, line 392 392: def to_yaml( opts = {} ) 393: opts[:UseFold] = true if opts.respond_to? :[] 394: self.class.text_processor_fields.each do |f| 395: v = instance_variable_get( '@' + f ) 396: if v.is_a? self.class.text_processor 397: instance_eval %{ 398: def @#{ f }.to_yaml( opts = {} ) 399: s = self.to_str 400: def s.to_yaml_style; :literal; end 401: s.to_yaml( opts ) 402: end 403: } 404: end 405: end 406: to_yaml_orig( opts ) 407: end