Class: Fronde::Index
- Inherits:
-
Object
- Object
- Fronde::Index
- Defined in:
- lib/fronde/index.rb,
lib/fronde/index/org_generator.rb,
lib/fronde/index/atom_generator.rb
Overview
Reopen Index class to embed Atom feeds sepecific methods
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
Instance Method Summary collapse
- #all_tags ⇒ Object
- #blog_home_page ⇒ Object
- #emacs_keywords ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(project) ⇒ Index
constructor
A new instance of Index.
- #sort_by(kind) ⇒ Object
- #to_atom(index_name = 'index') ⇒ Object
- #to_org(index_name = 'index') ⇒ Object (also: #to_s)
- #write_all_feeds(verbose: true) ⇒ Object
- #write_all_org(verbose: true) ⇒ Object
- #write_atom(index_name) ⇒ Object
- #write_org(index_name) ⇒ Object
Constructor Details
#initialize(project) ⇒ Index
Returns a new instance of Index.
13 14 15 16 17 18 19 20 21 |
# File 'lib/fronde/index.rb', line 13 def initialize(project) @project = project @index = { 'index' => [] } @entries = [] @tags_names = {} @date = Time.now generate_feeds if @project.blog? sort_feeds! end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
11 12 13 |
# File 'lib/fronde/index.rb', line 11 def date @date end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
11 12 13 |
# File 'lib/fronde/index.rb', line 11 def project @project end |
Class Method Details
Instance Method Details
#all_tags ⇒ Object
23 24 25 |
# File 'lib/fronde/index.rb', line 23 def @index.keys.reject { |tag| tag == 'index' } end |
#blog_home_page ⇒ Object
9 10 11 |
# File 'lib/fronde/index/org_generator.rb', line 9 def blog_home_page org_index @project['title'], '__HOME_PAGE__', @entries.map(&:to_h) end |
#emacs_keywords ⇒ Object
47 48 49 |
# File 'lib/fronde/index.rb', line 47 def emacs_keywords @tags_names.map { |slug, title| "#{title}\x1f#{slug}" }.join("\x1e") end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/fronde/index.rb', line 27 def empty? @index['index'].empty? end |
#sort_by(kind) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fronde/index.rb', line 31 def sort_by(kind) accepted_values = %i[name weight] unless accepted_values.include?(kind) error_msg = I18n.t( 'fronde.error.index.wrong_sort_kind', kind: kind, accepted_values: accepted_values.inspect ) raise ArgumentError, error_msg end [:"by_#{kind}"].map do |tag| @tags_names[tag] + " (#{@index[tag].length})" end.reverse # Reverse in order to have most important or A near next prompt # and avoid to scroll to find the beginning of the list. end |
#to_atom(index_name = 'index') ⇒ Object
8 9 10 11 12 13 |
# File 'lib/fronde/index/atom_generator.rb', line 8 def to_atom(index_name = 'index') entries = @index[index_name][0...10].map(&:to_h) return atom_index(entries) if index_name == 'index' atom_file(index_name, entries) end |
#to_org(index_name = 'index') ⇒ Object Also known as: to_s
13 14 15 16 17 18 19 20 |
# File 'lib/fronde/index/org_generator.rb', line 13 def to_org(index_name = 'index') return if index_name == 'index' org_index( @tags_names[index_name], index_name, (@index[index_name] || []).map(&:to_h) ) end |
#write_all_feeds(verbose: true) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/fronde/index/atom_generator.rb', line 21 def write_all_feeds(verbose: true) FileUtils.mkdir_p "#{@project.publication_path}/feeds" @index.each_key do |tag| write_atom(tag) puts I18n.t('fronde.index.atom_generated', tag:) if verbose end end |
#write_all_org(verbose: true) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/fronde/index/org_generator.rb', line 29 def write_all_org(verbose: true) FileUtils.mkdir_p "#{@project['path']}/tags" @index.each_key do |tag| write_org(tag) puts I18n.t('fronde.index.index_generated', tag:) if verbose end write_blog_home_page(verbose) end |