Class Hobix::BaseContent
In: lib/hobix/base.rb
Parent: Object

Methods

Included Modules

BaseProperties

External Aliases

to_yaml -> to_yaml_orig

Public Class methods

[Source]

     # File lib/hobix/base.rb, line 319
319:     def self.link_format( e ); e.id; end

Load the weblog entry from a file.

[Source]

     # 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.

[Source]

     # 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

[Source]

     # File lib/hobix/base.rb, line 312
312:     def initialize; yield self if block_given?; end

[Source]

     # File lib/hobix/base.rb, line 327
327:     def self.no_implicit_tags
328:       @@no_implicit_tags = true
329:     end

[Source]

     # File lib/hobix/base.rb, line 336
336:     def self.root_tag=( tag )
337:       @@root_tag = tag
338:     end

[Source]

     # File lib/hobix/base.rb, line 347
347:     def self.split_implicit_tags
348:       @@split_implicit_tags = true
349:     end

Accessor which returns the text processor used for untyped strings in Entry fields. (defaults to RedCloth.)

[Source]

     # File lib/hobix/base.rb, line 416
416:     def self.text_processor; RedCloth; end

Returns an Array of fields to which the text processor applies.

[Source]

     # 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

[Source]

     # 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

[Source]

     # 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

Public Instance methods

[Source]

     # File lib/hobix/base.rb, line 317
317:     def base_id; File.basename( id ) if id; end

return canonical tags, i.e. tags that are forced and that are deduced from the entry path

[Source]

     # File lib/hobix/base.rb, line 374
374:     def canonical_tags( path=nil )
375:       ( force_tags + path_to_tags( path || self.id ) ).uniq
376:     end

[Source]

     # File lib/hobix/base.rb, line 313
313:     def day_id; created.strftime( "%Y/%m/%d" ) if created; end

[Source]

     # File lib/hobix/base.rb, line 320
320:     def force_tags; []; end

[Source]

     # File lib/hobix/base.rb, line 314
314:     def month_id; created.strftime( "%Y/%m" ) if created; 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

[Source]

     # 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

[Source]

     # File lib/hobix/base.rb, line 316
316:     def section_id; File.dirname( id ) if id; end

[Source]

     # File lib/hobix/base.rb, line 378
378:     def tags;( canonical_tags + Array( @tags ) ).uniq; end

[Source]

     # 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

[Source]

     # File lib/hobix/base.rb, line 315
315:     def year_id; created.strftime( "%Y" ) if created; end

[Validate]