Class: Hobix::BaseContent
Constant Summary
collapse
- @@no_implicit_tags =
If set to true, tags won’t be deduced from the entry id
false
- @@root_tag =
When using implicit tag, the blog root (i.e) is not considered unless you set the value of @@root_tag to what you need.
nil
- @@split_implicit_tags =
When computing so-called implicit ‘implicit-tag’, whether or not we should split the path into several tags (default: false)
false
Class Method Summary
collapse
Instance Method Summary
collapse
append_features, #property_map, #to_yaml_properties
Constructor Details
#initialize {|_self| ... } ⇒ BaseContent
Returns a new instance of BaseContent.
312
|
# File 'lib/hobix/base.rb', line 312
def initialize; yield self if block_given?; end
|
Class Method Details
319
|
# File 'lib/hobix/base.rb', line 319
def self.link_format( e ); e.id; end
|
.load(file) ⇒ Object
Load the weblog entry from a file.
410
411
412
|
# File 'lib/hobix/base.rb', line 410
def self.load( file )
File.open( file ) { |f| YAML::load( f ) }
end
|
.maker(val) ⇒ Object
Factory method for generating Entry classes from a hash. Used by the YAML loader.
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
# File 'lib/hobix/base.rb', line 425
def self.maker( val )
self::text_processor_fields.each do |f|
if val[f].respond_to? :value
str = val[f].value
def str.to_html
self
end
val[f] = str
elsif val[f].respond_to? :to_str
val[f] = self::text_processor.new( val[f].to_str )
end
end
YAML::object_maker( self, val )
end
|
327
328
329
|
# File 'lib/hobix/base.rb', line 327
def self.no_implicit_tags
@@no_implicit_tags = true
end
|
.root_tag=(tag) ⇒ Object
336
337
338
|
# File 'lib/hobix/base.rb', line 336
def self.root_tag=( tag )
@@root_tag = tag
end
|
347
348
349
|
# File 'lib/hobix/base.rb', line 347
def self.split_implicit_tags
@@split_implicit_tags = true
end
|
.text_processor ⇒ Object
Accessor which returns the text processor used for untyped strings in Entry fields. (defaults to RedCloth
.)
416
|
# File 'lib/hobix/base.rb', line 416
def self.text_processor; RedCloth; end
|
.text_processor_fields ⇒ Object
Returns an Array of fields to which the text processor applies.
418
419
420
421
422
|
# File 'lib/hobix/base.rb', line 418
def self.text_processor_fields
self.properties.map do |name, opts|
name.to_s if opts and opts[:text_processor]
end.compact
end
|
.url_link(e, url = nil, ext = nil) ⇒ Object
318
|
# File 'lib/hobix/base.rb', line 318
def self.url_link( e, url = nil, ext = nil ); "#{ url }/#{ link_format e }#{ '.' + ext if ext }"; end
|
.yaml_type(tag) ⇒ Object
380
381
382
383
384
385
386
387
388
389
|
# File 'lib/hobix/base.rb', line 380
def self.yaml_type( tag )
if tag =~ /^tag:([^:]+):(.+)$/
define_method( :to_yaml_type ) { "!#$1/#$2" }
YAML::add_domain_type( $1, $2 ) { |t, v| self.maker( v ) }
end
end
|
Instance Method Details
#base_id ⇒ Object
317
|
# File 'lib/hobix/base.rb', line 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
374
375
376
|
# File 'lib/hobix/base.rb', line 374
def canonical_tags( path=nil )
( force_tags + path_to_tags( path || self.id ) ).uniq
end
|
#day_id ⇒ Object
313
|
# File 'lib/hobix/base.rb', line 313
def day_id; created.strftime( "%Y/%m/%d" ) if created; end
|
320
|
# File 'lib/hobix/base.rb', line 320
def force_tags; []; end
|
#month_id ⇒ Object
314
|
# File 'lib/hobix/base.rb', line 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
358
359
360
361
362
363
364
365
366
367
368
|
# File 'lib/hobix/base.rb', line 358
def path_to_tags( path )
return [] if @@no_implicit_tags
return [] if path.nil?
if @@split_implicit_tags
tags_array = path.split("/").find_all { |e| e.size > 0 }
tags_array.pop else
tags_array = [ File.dirname( path )]
end
tags_array.map { |e| e == '.' ? @@root_tag : e }.compact
end
|
#section_id ⇒ Object
316
|
# File 'lib/hobix/base.rb', line 316
def section_id; File.dirname( id ) if id; end
|
378
|
# File 'lib/hobix/base.rb', line 378
def tags;( canonical_tags + Array( @tags ) ).uniq; end
|
#to_yaml(opts = {}) ⇒ Object
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
# File 'lib/hobix/base.rb', line 392
def to_yaml( opts = {} )
opts[:UseFold] = true if opts.respond_to? :[]
self.class.text_processor_fields.each do |f|
v = instance_variable_get( '@' + f )
if v.is_a? self.class.text_processor
instance_eval %{
def @#{ f }.to_yaml( opts = {} )
s = self.to_str
def s.to_yaml_style; :literal; end
s.to_yaml( opts )
end
}
end
end
to_yaml_orig( opts )
end
|
#to_yaml_orig ⇒ Object
391
|
# File 'lib/hobix/base.rb', line 391
alias to_yaml_orig to_yaml
|
#year_id ⇒ Object
315
|
# File 'lib/hobix/base.rb', line 315
def year_id; created.strftime( "%Y" ) if created; end
|