Class: Hobix::Weblog
- Inherits:
-
Object
- Object
- Hobix::Weblog
- Includes:
- BaseProperties
- Defined in:
- lib/hobix/base.rb,
lib/hobix/weblog.rb,
lib/hobix/out/okaynews.rb,
lib/hobix/plugin/calendar.rb,
lib/hobix/publish/replicate.rb
Overview
respond to the same methods.
Defined Under Namespace
Classes: AuthorNotFound
Constant Summary collapse
- @@entry_classes =
[]
Instance Attribute Summary collapse
-
#hobix_yaml ⇒ Object
readonly
Returns the value of attribute hobix_yaml.
-
#path ⇒ Object
Returns the value of attribute path.
-
#updated_pages ⇒ Object
readonly
Returns the value of attribute updated_pages.
Class Method Summary collapse
- .add_entry_class(c) ⇒ Object
-
.load(hobix_yaml) ⇒ Object
Load the weblog information from a YAML file and
start
the Weblog.
Instance Method Summary collapse
- #authorize(user, pass) ⇒ Object
-
#build_pages(page_name) {|vars| ... } ⇒ Object
Used by
regenerate
to construct the vars hash by calling the appropriate skel method for each page. - #central_ext ⇒ Object
- #central_prefix ⇒ Object
-
#commit_to_git ⇒ Object
Method to commit to the local git repo and push pure happiness to the remote server named blahg (which should be of webserving character and a pleasant demeanor).
- #default_central_ext ⇒ Object
- #default_central_prefix ⇒ Object
- #default_entry_class ⇒ Object
- #default_entry_path ⇒ Object
- #default_index_class ⇒ Object
- #default_lib_path ⇒ Object
- #default_output_path ⇒ Object
- #default_skel_path ⇒ Object
- #entry_class(tag = nil) ⇒ Object
- #entry_path ⇒ Object
-
#expand_path(path) ⇒ Object
Translate paths relative to the weblahhg’s URL.
- #facet_for(app) ⇒ Object
-
#facets ⇒ Object
Returns an Array of all facet plugins in use.
- #index_class(tag = nil) ⇒ Object
- #join_path(prefix, suffix) ⇒ Object
- #lib_path ⇒ Object
- #link ⇒ Object
- #linklist ⇒ Object
-
#load_and_validate_entry(entry_id) ⇒ Object
Loads an entry from
storage
, first validating that the author is listed in the weblog config. -
#method_missing(methId, *args) ⇒ Object
For convenience, storage queries can be made through the Weblog class.
-
#output_entry_map ⇒ Object
Built from the map of output destinations described by
output_map
, this map pairs entry IDs against their canonical destinations. -
#output_map ⇒ Object
Reads
skel_path
for templates and builds a hash of all the various output files which will be generated. - #output_path ⇒ Object
-
#outputs ⇒ Object
Returns an Array of all output plugins in use.
-
#p_publish(obj) ⇒ Object
Prints publication information the screen.
-
#p_publish_orig ⇒ Object
Prints publication information the screen.
-
#publishers ⇒ Object
Returns an Array of all publisher plugins in use.
-
#regenerate(how = nil) ⇒ Object
Regenerates the weblog, processing templates in
skel_path
with the data found inentry_path
, storing output inoutput_path
. -
#reset_output_map ⇒ Object
Clears the hash used to cache the results of
output_map
. - #retouch(only_path = nil, how = nil) ⇒ Object
-
#save(file = @hobix_yaml) ⇒ Object
Save the weblog configuration to its hobix.yaml (or optionally provide a path where you would like to save.).
-
#sections(opts = nil) ⇒ Object
Receive a Hash pairing all section ids with the options for that section.
-
#sections_ignored ⇒ Object
Returns an Array of entry paths ignored by general querying.
-
#sections_sorts ⇒ Object
Returns a hash of special sorting cases.
-
#setup ⇒ Object
Sets up a weblog.
-
#skel_daily(path_storage, section_path) ⇒ Object
Handler for templates with ‘daily’ prefix.
-
#skel_entry(path_storage, section_path) ⇒ Object
Handler for templates with ‘entry’ prefix.
-
#skel_index(path_storage, section_path) {|:page => page, :entries => index_entries| ... } ⇒ Object
Handler for templates with ‘index’ prefix.
-
#skel_monthly(path_storage, section_path) ⇒ Object
Handler for templates with ‘monthly’ prefix.
- #skel_path ⇒ Object
-
#skel_section(path_storage, section_path) ⇒ Object
Handler for templates with ‘section’ prefix.
-
#skel_sidebar(path_storage, section_path) ⇒ Object
generate all the sidebar calendar files.
-
#skel_tags(path_storage, section_path) ⇒ Object
Handler for templates with ‘tags’ prefix.
-
#skel_yearly(path_storage, section_path) ⇒ Object
Handler for templates with ‘yearly’ prefix.
-
#start(hobix_yaml) ⇒ Object
After the weblog is initialize, the
start
method is called with the full system path to the directory containing the configuration. -
#storage ⇒ Object
Returns the storage plugin currently in use.
- #to_okaynews(entries) ⇒ Object
-
#to_yaml_type ⇒ Object
Returns the YAML type information, which expands to tag:hobix.com,2004:weblog.
Methods included from BaseProperties
append_features, #property_map, #to_yaml_properties
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methId, *args) ⇒ Object
For convenience, storage queries can be made through the Weblog class. Queries will return the full Entry data, though, so it’s best to use this only when you’re scripting and need data quick.
861 862 863 864 865 866 867 |
# File 'lib/hobix/weblog.rb', line 861 def method_missing( methId, *args ) if storage.respond_to? methId storage.method( methId ).call( *args ).collect do |e| load_and_validate_entry( e.id ) end end end |
Instance Attribute Details
#hobix_yaml ⇒ Object (readonly)
Returns the value of attribute hobix_yaml.
317 318 319 |
# File 'lib/hobix/weblog.rb', line 317 def hobix_yaml @hobix_yaml end |
#path ⇒ Object
Returns the value of attribute path.
316 317 318 |
# File 'lib/hobix/weblog.rb', line 316 def path @path end |
#updated_pages ⇒ Object (readonly)
Returns the value of attribute updated_pages.
94 95 96 |
# File 'lib/hobix/publish/replicate.rb', line 94 def updated_pages @updated_pages end |
Class Method Details
.add_entry_class(c) ⇒ Object
295 296 297 |
# File 'lib/hobix/base.rb', line 295 def self.add_entry_class( c ) @@entry_classes << c end |
.load(hobix_yaml) ⇒ Object
Load the weblog information from a YAML file and start
the Weblog.
411 412 413 414 415 416 |
# File 'lib/hobix/weblog.rb', line 411 def Weblog::load( hobix_yaml ) hobix_yaml = File.( hobix_yaml ) weblog = YAML::load( File::open( hobix_yaml ) ) weblog.start( hobix_yaml ) weblog end |
Instance Method Details
#authorize(user, pass) ⇒ Object
853 854 855 856 |
# File 'lib/hobix/weblog.rb', line 853 def ( user, pass ) require 'digest/sha1' [user]['password'] == Digest::SHA1.new( pass ) end |
#build_pages(page_name) {|vars| ... } ⇒ Object
Used by regenerate
to construct the vars hash by calling the appropriate skel method for each page.
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/hobix/weblog.rb', line 432 def build_pages( page_name ) vars = {} paths = page_name.split( '/' ) loop do try_page = paths.join( '_' ).gsub('-','_') if respond_to? "skel_#{ try_page }" section_path = File.dirname( page_name ) path_storage = storage.path_storage( section_path ) method( "skel_#{ try_page }" ).call( path_storage, section_path ) do |vars| vars[:weblog] = self raise TypeError, "No `page' variable returned from skel_#{ try_page }." unless vars[:page] yield vars end return end break unless paths.slice!( -2 ) ## go up a directory end vars[:weblog] = self vars[:page] = Page.new( page_name ) vars[:page]. = Time.now yield vars end |
#central_ext ⇒ Object
364 |
# File 'lib/hobix/weblog.rb', line 364 def central_ext; @central_ext =~ /^\w*$/ ? @central_ext.untaint : default_central_ext; end |
#central_prefix ⇒ Object
363 |
# File 'lib/hobix/weblog.rb', line 363 def central_prefix; @central_prefix =~ /^[\w\.]+$/ ? @central_prefix.untaint : default_central_prefix; end |
#commit_to_git ⇒ Object
Method to commit to the local git repo and push pure happiness to the remote server named blahg (which should be of webserving character and a pleasant demeanor).
661 662 663 664 665 |
# File 'lib/hobix/weblog.rb', line 661 def commit_to_git puts `git add .` puts `git commit -a -m "New poshts for the syhtt"` puts `git push blahg master` end |
#default_central_ext ⇒ Object
355 |
# File 'lib/hobix/weblog.rb', line 355 def default_central_ext; "html"; end |
#default_central_prefix ⇒ Object
354 |
# File 'lib/hobix/weblog.rb', line 354 def default_central_prefix; "entry"; end |
#default_entry_class ⇒ Object
356 |
# File 'lib/hobix/weblog.rb', line 356 def default_entry_class; "Hobix::Entry"; end |
#default_entry_path ⇒ Object
350 |
# File 'lib/hobix/weblog.rb', line 350 def default_entry_path; "entries"; end |
#default_index_class ⇒ Object
357 |
# File 'lib/hobix/weblog.rb', line 357 def default_index_class; "Hobix::IndexEntry"; end |
#default_lib_path ⇒ Object
353 |
# File 'lib/hobix/weblog.rb', line 353 def default_lib_path; "lib"; end |
#default_output_path ⇒ Object
352 |
# File 'lib/hobix/weblog.rb', line 352 def default_output_path; "htdocs"; end |
#default_skel_path ⇒ Object
351 |
# File 'lib/hobix/weblog.rb', line 351 def default_skel_path; "skel"; end |
#entry_class(tag = nil) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/hobix/weblog.rb', line 365 def entry_class( tag = nil ) tag = @entry_class =~ /^[\w:]+$/ ? @entry_class.untaint : default_entry_class unless tag found_class = nil raise @@entry_classes.inspect if @@entry_classes found_class = @@entry_classes.find do |c| tag == c.name.split( '::' ).last.downcase end end begin found_class || Hobix.const_find( tag ) rescue NameError => e raise NameError, "No such entry class #{ tag }" end end |
#entry_path ⇒ Object
359 |
# File 'lib/hobix/weblog.rb', line 359 def entry_path; File.( @entry_path || default_entry_path, @path ).untaint; end |
#expand_path(path) ⇒ Object
Translate paths relative to the weblahhg’s URL. This is especially important if a weblog isn’t at the root directory for a domain.
406 407 408 |
# File 'lib/hobix/weblog.rb', line 406 def ( path ) File.( path.gsub( /^\/+/, '' ), self.link.path.gsub( /\/*$/, '/' ) ).gsub( /^C:/, '') end |
#facet_for(app) ⇒ Object
489 490 491 492 |
# File 'lib/hobix/weblog.rb', line 489 def facet_for( app ) facets.each { |p| return if p.get app } Hobix::BaseFacet.not_found app end |
#facets ⇒ Object
Returns an Array of all facet plugins in use. (There can be many.)
485 486 487 |
# File 'lib/hobix/weblog.rb', line 485 def facets @plugins.find_all { |p| p.is_a? BaseFacet } end |
#index_class(tag = nil) ⇒ Object
383 384 385 386 387 388 389 390 |
# File 'lib/hobix/weblog.rb', line 383 def index_class( tag = nil ) tag = @index_class =~ /^[\w:]+$/ ? @index_class.untaint : default_index_class unless tag begin Hobix.const_find( tag ) rescue NameError => e raise NameError, "No such index class #{ tag }" end end |
#join_path(prefix, suffix) ⇒ Object
832 833 834 835 836 837 838 839 |
# File 'lib/hobix/weblog.rb', line 832 def join_path( prefix, suffix ) case prefix when '', '.' suffix else "#{ prefix }/#{ suffix }" end end |
#lib_path ⇒ Object
362 |
# File 'lib/hobix/weblog.rb', line 362 def lib_path; File.( @lib_path || default_lib_path, @path ).untaint; end |
#link ⇒ Object
392 393 394 |
# File 'lib/hobix/weblog.rb', line 392 def link URI::parse( @link.gsub( /\/$/, '' ) ).extend Hobix::UriStr end |
#linklist ⇒ Object
396 397 398 399 400 401 402 |
# File 'lib/hobix/weblog.rb', line 396 def linklist if @linklist.class == ::Array YAML::transfer( 'hobix.com,2004/linklist', {'links' => @linklist} ) else @linklist end end |
#load_and_validate_entry(entry_id) ⇒ Object
Loads an entry from storage
, first validating that the author is listed in the weblog config.
845 846 847 848 849 850 851 |
# File 'lib/hobix/weblog.rb', line 845 def load_and_validate_entry( entry_id ) entry = storage.load_entry( entry_id ) unless .has_key?( entry. ) raise AuthorNotFound, "Invalid author '#{ entry. }' found in entry #{ entry_id }" end entry end |
#output_entry_map ⇒ Object
Built from the map of output destinations described by output_map
, this map pairs entry IDs against their canonical destinations. The @central_prefix and @central_ext variables determine what output is canonical.
552 553 554 555 |
# File 'lib/hobix/weblog.rb', line 552 def output_entry_map output_map @output_entry_map end |
#output_map ⇒ Object
Reads skel_path
for templates and builds a hash of all the various output files which will be generated. This method will cache the output_map once. Subsequent calls to output_map
will quickly return the cached hash. To reset the cache, use reset_output_map
.
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/hobix/weblog.rb', line 501 def output_map @output_map ||= nil return @output_map if @output_map path_watch = {} @output_entry_map = {} Find::find( skel_path ) do |path| path.untaint if File.basename(path)[0] == ?. Find.prune elsif not FileTest.directory? path tpl_path = path.gsub( /^#{ Regexp::quote( skel_path ) }\/?/, '' ) output = outputs.detect { |p| if tpl_path =~ /\.#{ p.extension }$/; tpl_path = $`; end } if output ## Figure out template extension and output filename page_name, tpl_ext = tpl_path.dup, '' while page_name =~ /\.\w+$/; page_name = $`; tpl_ext = $& + tpl_ext; end next if tpl_ext.empty? ## Build the output pages build_pages( page_name ) do |vars| ## Extension and Path vars[:page].add_ext( tpl_ext ) vars[:template] = path vars[:output] = output eid = ( vars[:entry] && vars[:entry].id ) || page_name if not @output_entry_map[ eid ] @output_entry_map[ eid ] = vars elsif tpl_ext.split( '.' )[1] == central_ext @output_entry_map[ eid ] = vars end ## If output by a deeper page, skip pub_name, = path_watch[vars[:page].link] next if pub_name and !( vars[:page].link.index( page_name ) == 0 and page_name.length > pub_name.length ) path_watch[vars[:page].link] = [page_name, vars] end end end end @output_map = {} path_watch.each_value do |page_name, vars| @output_map[page_name] ||= [] @output_map[page_name] << vars end @output_map end |
#output_path ⇒ Object
361 |
# File 'lib/hobix/weblog.rb', line 361 def output_path; File.( @output_path || default_output_path, @path ).untaint; end |
#outputs ⇒ Object
Returns an Array of all output plugins in use. (There can be many.)
473 474 475 |
# File 'lib/hobix/weblog.rb', line 473 def outputs @plugins.find_all { |p| p.is_a? BaseOutput } end |
#p_publish(obj) ⇒ Object
Prints publication information the screen. Override this if you want to suppress output or change the display.
871 872 873 |
# File 'lib/hobix/weblog.rb', line 871 def p_publish( obj ) puts "## Page: #{ obj.link }, updated #{ obj.updated }" end |
#p_publish_orig ⇒ Object
Prints publication information the screen. Override this if you want to suppress output or change the display.
96 97 98 |
# File 'lib/hobix/publish/replicate.rb', line 96 def p_publish( obj ) puts "## Page: #{ obj.link }, updated #{ obj.updated }" end |
#publishers ⇒ Object
Returns an Array of all publisher plugins in use. (There can be many.)
479 480 481 |
# File 'lib/hobix/weblog.rb', line 479 def publishers @plugins.find_all { |p| p.is_a? BasePublish } end |
#regenerate(how = nil) ⇒ Object
Regenerates the weblog, processing templates in skel_path
with the data found in entry_path
, storing output in output_path
.
The how parameter dictates how this is done, Currently, if how is nil the weblog is completely regen’d. If it is :update, the weblog is only upgen’d.
How Updates Work
It’s very important to know how updates work, especially if you are writing custom skel methods or devious new kinds of templates. When performing an update, this method will skip pages if the following conditions are met:
-
The Page object for a given output page must have its
updated
timestamp set. -
The output file pointed to by the Page object must already exist.
-
The
updated
timestamp must be older than than the modification time of the output file. -
The modification time of the input template must be older than than the modification time of the output file.
To ensure that your custom methods and templates are qualifying to be skipped on an upgen, be sure to set the updated
timestamp of the Page object to the latest date of the content’s modification.
585 586 587 |
# File 'lib/hobix/weblog.rb', line 585 def regenerate( how = nil ) retouch nil, how end |
#reset_output_map ⇒ Object
Clears the hash used to cache the results of output_map
.
495 |
# File 'lib/hobix/weblog.rb', line 495 def reset_output_map; @output_map = nil; end |
#retouch(only_path = nil, how = nil) ⇒ Object
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
# File 'lib/hobix/weblog.rb', line 588 def retouch( only_path = nil, how = nil ) published = {} published_types = [] output_map.each do |page_name, outputs| puts "[Building #{ page_name } pages]" outputs.each do |vars| full_out_path = File.join( output_path, vars[:page].link.split( '/' ) ) ## If retouching, skip pages outside of path next if only_path and vars[:page].link.index( "/" + only_path ) != 0 ## If updating, skip any that are unchanged next if how == :update and File.exists?( full_out_path ) and File.mtime( vars[:template] ) < File.mtime( full_out_path ) and ( vars[:page].updated.nil? or vars[:page].updated < File.mtime( full_out_path ) ) p_publish vars[:page] vars.keys.each do |var_name| case var_name.to_s when /entry$/ unless vars[:no_load] vars[var_name] = load_and_validate_entry( vars[var_name].id ) end when /entries$/ unless vars[:no_load] vars[var_name].collect! do |e| load_and_validate_entry( e.id ) end end vars[var_name].extend Hobix::EntryEnum end end ## Publish the page vars = vars.dup output = vars.delete( :output ) template = vars.delete( :template ) txt = output.load( template, vars ) ## A plugin perhaps needs to change the output page name full_out_path = File.join( output_path, vars[:page].link.split( '/' ) ) saved_umask = File.umask( 0002 ) rescue nil begin File.makedirs( File.dirname( full_out_path ) ) File.open( full_out_path, 'w' ) do |f| f << txt end ensure File.umask( saved_umask ) rescue nil end published[vars[:page].link] = vars[:page] published_types << page_name end end published_types.uniq! publishers.each do |p| if p.respond_to? :watch if p.watch & published_types != [] p.publish( published ) end else p.publish( published ) end end commit_to_git if @git reset_output_map end |
#save(file = @hobix_yaml) ⇒ Object
Save the weblog configuration to its hobix.yaml (or optionally provide a path where you would like to save.)
420 421 422 423 424 425 426 427 428 |
# File 'lib/hobix/weblog.rb', line 420 def save( file = @hobix_yaml ) unless file raise ArgumentError, "Missing argument: path to save configuration (0 of 1)" end File::open( file, 'w' ) do |f| YAML::dump( self, f ) end self end |
#sections(opts = nil) ⇒ Object
Receive a Hash pairing all section ids with the options for that section.
786 787 788 789 790 791 792 793 794 795 |
# File 'lib/hobix/weblog.rb', line 786 def sections( opts = nil ) sections = Marshal::load( Marshal::dump( @sections ) ) observes = !sections.values.detect { |s| s['observe'] } storage.sections.each do |s| sections[s] ||= {} sections[s]['observe'] ||= sections[s].has_key?( 'ignore' ) ? !sections[s]['ignore'] : observes sections[s]['ignore'] ||= !sections[s]['observe'] end sections end |
#sections_ignored ⇒ Object
Returns an Array of entry paths ignored by general querying. Storage plugins must withhold these entries from queries, unless the :all => true setting is passed to the query.
811 812 813 814 815 |
# File 'lib/hobix/weblog.rb', line 811 def sections_ignored sections.collect do |k, v| k if v['ignore'] end.compact end |
#sections_sorts ⇒ Object
Returns a hash of special sorting cases. Key is the entry path, value is the sorting method. Storage plugins must honor these default sorts.
800 801 802 803 804 805 806 |
# File 'lib/hobix/weblog.rb', line 800 def sections_sorts @sections.inject( {} ) do |sorts, set| k, v = set sorts[k] = v['sort_by'] if v['sort_by'] sorts end end |
#setup ⇒ Object
Sets up a weblog. Should only be run once (which Hobix performs automatically upon blog creation).
457 458 459 460 461 462 463 |
# File 'lib/hobix/weblog.rb', line 457 def setup @plugins.each do |p| if p.respond_to? :setup p.setup end end end |
#skel_daily(path_storage, section_path) ⇒ Object
Handler for templates with ‘daily’ prefix. These templates will receive a list of entries for each day that has at least one entry created in its time period. This handler requests daily pages to be output as ‘/%Y/%m/%d.ext’.
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'lib/hobix/weblog.rb', line 683 def skel_daily( path_storage, section_path ) entry_range = path_storage.find first_time, last_time = entry_range.last.created, entry_range.first.created start = Time.mktime( first_time.year, first_time.month, first_time.day, 0, 0, 0 ) + 1 stop = Time.mktime( last_time.year, last_time.month, last_time.day, 23, 59, 59 ) days = [] one_day = 24 * 60 * 60 until start > stop day_entries = path_storage.within( start, start + one_day - 1 ) days << [day_entries.last.created, day_entries] unless day_entries.empty? start += one_day end days.extend Hobix::Enumerable days.each_with_neighbors do |prev, curr, nextd| page = Page.new( curr[0].strftime( "%Y/%m/%d" ), section_path ) page.prev = prev[0].strftime( "%Y/%m/%d" ) if prev page.next = nextd[0].strftime( "%Y/%m/%d" ) if nextd page. = curr[0] page.updated = path_storage.last_updated( curr[1] ) yield :page => page, :entries => curr[1] end end |
#skel_entry(path_storage, section_path) ⇒ Object
Handler for templates with ‘entry’ prefix. These templates will receive one entry for each entry in the weblog. The handler requests entry pages to be output as ‘/shortName.ext’.
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/hobix/weblog.rb', line 749 def skel_entry( path_storage, section_path ) all_entries = [path_storage.find] all_entries += sections_ignored.collect { |ign| path_storage.find( :all => true, :inpath => ign ) } all_entries.each do |entry_set| entry_set.extend Hobix::Enumerable entry_set.each_with_neighbors do |nexte, entry, prev| page = Page.new( entry.id ) page.prev = prev.id if prev page.next = nexte.id if nexte page. = entry.created page.updated = path_storage.updated( entry.id ) yield :page => page, :entry => entry end end end |
#skel_index(path_storage, section_path) {|:page => page, :entries => index_entries| ... } ⇒ Object
Handler for templates with ‘index’ prefix. These templates will receive entries loaded by Hobix::BaseStorage#lastn. Only one index page is requested by this handler.
670 671 672 673 674 675 676 677 |
# File 'lib/hobix/weblog.rb', line 670 def skel_index( path_storage, section_path ) index_entries = path_storage.lastn( @lastn ) page = Page.new( 'index', section_path ) page.prev = index_entries.last.created.strftime( "%Y/%m/index" ) page. = index_entries.first.created page.updated = path_storage.last_updated( index_entries ) yield :page => page, :entries => index_entries end |
#skel_monthly(path_storage, section_path) ⇒ Object
Handler for templates with ‘monthly’ prefix. These templates will receive a list of entries for each month that has at least one entry created in its time period. This handler requests monthly pages to be output as ‘/%Y/%m/index.ext’.
710 711 712 713 714 715 716 717 718 719 720 721 722 |
# File 'lib/hobix/weblog.rb', line 710 def skel_monthly( path_storage, section_path ) months = path_storage.get_months( path_storage.find ) months.extend Hobix::Enumerable months.each_with_neighbors do |prev, curr, nextm| entries = path_storage.within( curr[0], curr[1] ) page = Page.new( curr[0].strftime( "%Y/%m/index" ), section_path ) page.prev = prev[0].strftime( "%Y/%m/index" ) if prev page.next = nextm[0].strftime( "%Y/%m/index" ) if nextm page. = curr[1] page.updated = path_storage.last_updated( entries ) yield :page => page, :entries => entries end end |
#skel_path ⇒ Object
360 |
# File 'lib/hobix/weblog.rb', line 360 def skel_path; File.( @skel_path || default_skel_path, @path ).untaint; end |
#skel_section(path_storage, section_path) ⇒ Object
Handler for templates with ‘section’ prefix. These templates will receive all entries below a given directory. The handler requests will be output as ‘/section/index.ext’.
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
# File 'lib/hobix/weblog.rb', line 768 def skel_section( path_storage, section_path ) section_map = {} path_storage.all.each do |entry| dirs = entry.id.split( '/' ) while ( dirs.pop; dirs.first ) section = dirs.join( '/' ) section_map[ section ] ||= [] section_map[ section ] << entry end end section_map.each do |section, entries| page = Page.new( "/#{ section }/index" ) page.updated = path_storage.last_updated( entries ) yield :page => page, :entries => entries end end |
#skel_sidebar(path_storage, section_path) ⇒ Object
generate all the sidebar calendar files
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/hobix/plugin/calendar.rb', line 95 def ( path_storage, section_path ) months = path_storage.get_months(storage.find) months.extend Hobix::Enumerable months.each_with_neighbors do |prev, cur, nexxt| month_start, month_end, month_id = cur entries = path_storage.within(month_start, month_end) entry_path = SidebarCalendarPlugin.dir_to(month_start, false) page = Page.new( entry_path, section_path ) page. = month_start page.updated = Time.now #path_storage.last_modified(entries) page.prev = prev[0].strftime("/%Y/%m/") if prev page.next = nexxt[0].strftime("/%Y/%m/") if nexxt days = entries.map do |entry| day = entry.created Date.new(day.year, day.mon, day.day) end.uniq_c offset = (month_start.wday - (SidebarCalendarPlugin.start_on_monday? ? 1 : 0)) % 7 yield :page => page, :months => months, :month => month_start, :days => days, :offset => offset, :day_syms => SidebarCalendarPlugin.day_syms, :index => SidebarCalendarPlugin.point_to_index end end |
#skel_tags(path_storage, section_path) ⇒ Object
Handler for templates with ‘tags’ prefix. These templates will receive a tag with all entries tagged with it. The handler requests will be output as ‘/tags/<tag>/index.ext’.
820 821 822 823 824 825 826 827 828 829 830 |
# File 'lib/hobix/weblog.rb', line 820 def ( path_storage, section_path ) # Get a list of all known tags = path_storage.find( :all => true ).map { |e| e. }.flatten.uniq .each do |tag| entries = path_storage.find.find_all { |e| e..member? tag } page = Page.new( File::join( 'tags',tag,'index' ), section_path ) page.updated = path_storage.last_updated( entries ) yield :page => page, :entries => entries end end |
#skel_yearly(path_storage, section_path) ⇒ Object
Handler for templates with ‘yearly’ prefix. These templates will receive a list of entries for each month that has at least one entry created in its time period. This handler requests yearly pages to be output as ‘/%Y/index.ext’.
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/hobix/weblog.rb', line 728 def skel_yearly( path_storage, section_path ) entry_range = path_storage.find first_time, last_time = entry_range.last.created, entry_range.first.created years = (first_time.year..last_time.year).collect do |y| [ Time.mktime( y, 1, 1 ), Time.mktime( y + 1, 1, 1 ) - 1 ] end years.extend Hobix::Enumerable years.each_with_neighbors do |prev, curr, nextm| entries = path_storage.within( curr[0], curr[1] ) page = Page.new( curr[0].strftime( "%Y/index" ), section_path ) page.prev = prev[0].strftime( "%Y/index" ) if prev page.next = nextm[0].strftime( "%Y/index" ) if nextm page. = curr[1] page.updated = path_storage.last_updated( entries ) yield :page => page, :entries => entries end end |
#start(hobix_yaml) ⇒ Object
After the weblog is initialize, the start
method is called with the full system path to the directory containing the configuration.
This method sets up all the paths and loads the plugins.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/hobix/weblog.rb', line 323 def start( hobix_yaml ) @hobix_yaml = hobix_yaml @path = File.dirname( hobix_yaml ) @sections ||= {} if File.exists?( lib_path ) $LOAD_PATH << lib_path end @plugins = [] @requires.each do |req| opts = nil unless req.respond_to? :to_str req, opts = req.to_a.first end plugin_conf = File.join( @path, req.gsub( /\W+/, '.' ) ) if File.exists? plugin_conf puts "*** Loading #{ plugin_conf }" plugin_conf = YAML::load_file plugin_conf if opts opts.merge! plugin_conf else opts = plugin_conf end end @plugins += Hobix::BasePlugin::start( req, opts, self ) end end |
#storage ⇒ Object
Returns the storage plugin currently in use. (There can be only one per weblog.)
467 468 469 |
# File 'lib/hobix/weblog.rb', line 467 def storage @plugins.detect { |p| p.is_a? BaseStorage } end |
#to_okaynews(entries) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hobix/out/okaynews.rb', line 20 def to_okaynews( entries ) YAML::quick_emit( self.object_id ) do |out| out.map( "!okay/news/^feed" ) do |map| ['@title', '@tagline', '@link', '@period', '@created', '@issued', '@modified', '@authors', '@contributors' ].each do |m| map.add( m[1..-1], instance_variable_get( m ) ) end entries = entries.collect do |e| e = e.dup e. = @authors[e.] def e.to_yaml_type "!^entry" end e end map.add( 'entries', entries ) end end end |
#to_yaml_type ⇒ Object
Returns the YAML type information, which expands to tag:hobix.com,2004:weblog.
879 880 881 |
# File 'lib/hobix/weblog.rb', line 879 def to_yaml_type "!hobix.com,2004/weblog" end |