Class: Fronde::Source
- Inherits:
-
Object
- Object
- Fronde::Source
- Defined in:
- lib/fronde/source.rb,
lib/fronde/source/html.rb,
lib/fronde/source/gemini.rb
Overview
Wrapper for each possible project source. Must be subclassed by specific source type (like Gemini or HTML)
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #blog? ⇒ Boolean
- #exclude_file?(file_name) ⇒ Boolean
-
#initialize(source_config) ⇒ Source
constructor
A new instance of Source.
- #org_config ⇒ Object
-
#public_absolute_path ⇒ String
Return the absolute path as seen in User Agent.
-
#publication_path ⇒ String
Return the publication absolute path on file system.
- #recursive? ⇒ Boolean
- #source_for(file_name) ⇒ Object
- #source_for?(file_name) ⇒ Boolean
- #target_for(file_name) ⇒ Object
- #to_h ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(source_config) ⇒ Source
Returns a new instance of Source.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fronde/source.rb', line 7 def initialize(source_config) @config = { 'recursive' => true, 'is_blog' => false, 'domain' => CONFIG.get('domain'), 'atom_feed' => '', 'org-options' => { 'section-numbers' => 'nil', 'with-toc' => 'nil' } }.merge(source_config) clean_config render_heading end |
Class Method Details
.canonical_config(config) ⇒ Object
133 134 135 136 137 |
# File 'lib/fronde/source.rb', line 133 def canonical_config(config) config = { 'path' => config } if config.is_a?(String) config['type'] ||= 'html' config end |
.new_from_config(config) ⇒ Object
139 140 141 142 143 |
# File 'lib/fronde/source.rb', line 139 def new_from_config(config) klass_name = config['type'].capitalize klass = Kernel.const_get("::Fronde::Source::#{klass_name}") klass.new(config) end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/fronde/source.rb', line 20 def [](key) @config[key] end |
#[]=(key, value) ⇒ Object
24 25 26 |
# File 'lib/fronde/source.rb', line 24 def []=(key, value) @config[key] = value end |
#blog? ⇒ Boolean
36 37 38 |
# File 'lib/fronde/source.rb', line 36 def blog? !!@config['is_blog'] end |
#exclude_file?(file_name) ⇒ Boolean
87 88 89 90 91 92 93 94 95 |
# File 'lib/fronde/source.rb', line 87 def exclude_file?(file_name) # Obviously excluding index itself for blogs return true if file_name == File.join(@config['path'], 'index.org') exclusion_rules = @config['exclude'] return false unless exclusion_rules file_name.match? exclusion_rules end |
#org_config ⇒ Object
97 98 99 100 101 |
# File 'lib/fronde/source.rb', line 97 def org_config name = @config['name'] [{ 'name' => name, 'attributes' => org_project_config }, { 'name' => "#{name}-assets", 'attributes' => org_assets_config }] end |
#public_absolute_path ⇒ String
Return the absolute path as seen in User Agent.
The returned string always end with a slash (/).
Use #publication_path to locate published file on the file system.
126 127 128 129 130 |
# File 'lib/fronde/source.rb', line 126 def public_absolute_path return @config['public_absolute_path'] if @config['public_absolute_path'] @config['public_absolute_path'] = "/#{@config['target']}/".squeeze('/') end |
#publication_path ⇒ String
Return the publication absolute path on file system.
The returned string never end with a slash (/).
Use #public_absolute_path to get the absolute path of this project, as seen from a web browser.
111 112 113 114 115 116 |
# File 'lib/fronde/source.rb', line 111 def publication_path return @config['publication_path'] if @config['publication_path'] publish_in = [@config['folder'], @config['target']] @config['publication_path'] = publish_in.join('/').delete_suffix('/') end |
#recursive? ⇒ Boolean
32 33 34 |
# File 'lib/fronde/source.rb', line 32 def recursive? !!@config['recursive'] end |
#source_for(file_name) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fronde/source.rb', line 58 def source_for(file_name) relative_file_path = file_name.delete_prefix "#{publication_path}/" # file_name does not begin with source path. return if relative_file_path == file_name # Looks like a file at a deeper level, but current source is not # recursive. return if relative_file_path.include?('/') && !recursive? # Looks like a match. But does a source file for this one actually # exists? relative_source_path = relative_file_path.sub( /#{@config['ext']}\z/, '.org' ) source_path = File.join(@config['path'], relative_source_path) return unless File.file?(source_path) source_path end |
#source_for?(file_name) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fronde/source.rb', line 44 def source_for?(file_name) relative_file_path = file_name.delete_prefix "#{@config['path']}/" # file_name does not begin with source path. return false if relative_file_path == file_name # Looks like a file at a deeper level, but current source is not # recursive. return false if relative_file_path.include?('/') && !recursive? # We don’t check file if the file really exist as the current # check may be done before the file is actually written. true end |
#target_for(file_name) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/fronde/source.rb', line 78 def target_for(file_name) target = File. file_name target.delete_prefix! "#{Dir.pwd}/" target.sub!(/\.org\z/, @config['ext']) project_relative_path = @config['path'].delete_prefix("#{Dir.pwd}/") target.delete_prefix! "#{project_relative_path}/" public_absolute_path + target end |
#to_h ⇒ Object
40 41 42 |
# File 'lib/fronde/source.rb', line 40 def to_h @config end |
#type ⇒ Object
28 29 30 |
# File 'lib/fronde/source.rb', line 28 def type @config['type'] end |