Class: Zine::Site
- Inherits:
-
Object
- Object
- Zine::Site
- Defined in:
- lib/zine.rb
Overview
the site
Defined Under Namespace
Classes: MockYes
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Site options read from YAML during the initialisation of the class.
Instance Method Summary collapse
-
#build_site ⇒ Object
A dry run build that generates baseline data to compare changes to during editting/preview, then generate files where the source files change.
-
#build_site_forcing_writes ⇒ Object
Build the files of the site, generating files immeadiately, suitable for the initial build or complete rebuild.
-
#initialize ⇒ Site
constructor
Create a new instance of Site, called by CLI#init_site.
-
#make_template_bundle(type) ⇒ Object
Create a new instance of TemplateFiles, looking up the body template in @templates_by_name, defaults to the template named ‘default’.
-
#notice(file) ⇒ Object
Build the site, noticing this file as having changed Called by CLI#notice TODO: common function call across other methods.
- #write_markdown(default_name, src_dir, file) ⇒ Object
Constructor Details
#initialize ⇒ Site
Create a new instance of Site, called by CLI#init_site
17 18 19 20 21 |
# File 'lib/zine.rb', line 17 def initialize @templates_by_name = {} clean_option_paths end |
Instance Attribute Details
#options ⇒ Object (readonly)
Site options read from YAML during the initialisation of the class
14 15 16 |
# File 'lib/zine.rb', line 14 def @options end |
Instance Method Details
#build_site ⇒ Object
A dry run build that generates baseline data to compare changes to during editting/preview, then generate files where the source files change. Called by CLI#build
26 27 28 29 30 31 32 |
# File 'lib/zine.rb', line 26 def build_site init_templates FileUtils.mkdir_p @options['directories']['build'] # posts_and_guard is { posts: @post_array, guard: @guard } posts_and_guard = posts_and_headlines_without_writing preview posts_and_guard end |
#build_site_forcing_writes ⇒ Object
Build the files of the site, generating files immeadiately, suitable for the initial build or complete rebuild. Called by CLI#force
37 38 39 40 41 42 43 44 45 |
# File 'lib/zine.rb', line 37 def build_site_forcing_writes init_templates FileUtils.mkdir_p @options['directories']['build'] # posts_and_guard is { posts: @post_array, guard: @guard } posts_and_guard = write_posts_and_headlines housekeeping write_other_markdown_pages preview posts_and_guard end |
#make_template_bundle(type) ⇒ Object
Create a new instance of TemplateFiles, looking up the body template in @templates_by_name, defaults to the template named ‘default’
Called in PostsAndHeadlines.read_post_markdown_files, PostsAndHeadlines.one_new_post, PostsAndHeadlines.write_headline, PostsAndHeadlines.write_tags_and_headlines
Attributes
-
type
- The name of the template used for the body eg post
Eg
make_template_bundle 'post'
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/zine.rb', line 62 def make_template_bundle(type) TemplateFiles.new( if @templates_by_name.key?(type) @templates_by_name[type] else @templates_by_name['default'] end, @templates_by_name['header_partial'], @templates_by_name['footer_partial'] ) end |
#notice(file) ⇒ Object
Build the site, noticing this file as having changed Called by CLI#notice TODO: common function call across other methods
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/zine.rb', line 84 def notice(file) # build init_templates FileUtils.mkdir_p @options['directories']['build'] # posts_and_headlines_without_writing posts = Zine::PostsAndHeadlines.new self, @options # starts watcher posts_and_guard = posts.writeless guard = posts_and_guard[:guard] # build the file & add it to the upload array posts_dir = @options['directories']['posts'] file_to_notice = File.join posts_dir, file path_to_notice = File.join Dir.getwd, file_to_notice dest_path = posts.one_new_post file_to_notice, path_to_notice guard.notice(dest_path) # TODO: everywhere guard.listener_array.each(&:stop) # preview posts_and_guard -- no preview needed... return if @options['upload']['method'] == 'none' || (guard.delete_array.empty? && guard.upload_array.empty?) uploader = Zine::Upload.new(@options['directories']['build'], @options['upload'], guard.delete_array, guard.upload_array) uploader.upload_decision MockYes end |
#write_markdown(default_name, src_dir, file) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/zine.rb', line 115 def write_markdown(default_name, src_dir, file) dir = Pathname(File.dirname(file)).relative_path_from(Pathname(src_dir)) file_name = "#{File.basename(file, '.*')}.html" dest = File.join @options['directories']['build'], dir FileUtils.mkdir_p dest page = Zine::Page.new(file, File.join(dest, file_name), make_template_bundle(default_name), @options) page.process File end |