Class: Dropsite::SiteDir
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Attributes included from RenderHelper
Instance Method Summary collapse
-
#dirs ⇒ Object
All directories in this directory.
-
#file_type ⇒ Object
The file type is always ‘directory’.
-
#files ⇒ Object
All regular files in this directory.
-
#initialize(path, entries, site) ⇒ SiteDir
constructor
A new instance of SiteDir.
-
#page_assets_dir ⇒ Object
Directory to store extra files needed by the page rendered to represent this directory.
-
#page_dir ⇒ Object
Directory where the page will be written.
- #render ⇒ Object
-
#root? ⇒ Boolean
Is this the site root directory?.
-
#size ⇒ Object
The human readable size is blank.
- #to_s ⇒ Object
-
#write ⇒ Object
Writes the page for this directory, plus any additional files needed by the page.
Methods inherited from SiteItem
#<=>, #error, #name, #notice, #top_level?, #warning
Methods included from RenderHelper
#back_link, #each_parent_directory_link_tag, #get_binding, #image_tag, #javascript_include_tag, #link, #page_asset_image_tag, #page_assets_link_base, #parent_dir_name, #parent_directory_link_tag, #plugin_assets_link_base, #stylesheet_link_tag, #url_for
Constructor Details
#initialize(path, entries, site) ⇒ SiteDir
Returns a new instance of SiteDir.
6 7 8 9 10 11 |
# File 'lib/dropsite/site_dir.rb', line 6 def initialize(path, entries, site) @path = path == '/' ? '' : path @entries = entries @site = site @content = nil end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
4 5 6 |
# File 'lib/dropsite/site_dir.rb', line 4 def content @content end |
#entries ⇒ Object
Returns the value of attribute entries.
3 4 5 |
# File 'lib/dropsite/site_dir.rb', line 3 def entries @entries end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/dropsite/site_dir.rb', line 4 def path @path end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
4 5 6 |
# File 'lib/dropsite/site_dir.rb', line 4 def site @site end |
Instance Method Details
#dirs ⇒ Object
All directories in this directory
56 |
# File 'lib/dropsite/site_dir.rb', line 56 def dirs; entries.find_all {|e| e.is_a? SiteDir} end |
#file_type ⇒ Object
The file type is always ‘directory’
62 |
# File 'lib/dropsite/site_dir.rb', line 62 def file_type; 'directory' end |
#files ⇒ Object
All regular files in this directory
53 |
# File 'lib/dropsite/site_dir.rb', line 53 def files; entries.find_all {|e| e.is_a? SiteFile} end |
#page_assets_dir ⇒ Object
Directory to store extra files needed by the page rendered to represent this directory. This will almost always be the directory the page is in, except for the case of the root index page. Since the root index page is in Dropbox/Public and we don’t want to pollute that directory we put the assets in the root of the dropsite directory.
81 82 83 |
# File 'lib/dropsite/site_dir.rb', line 81 def page_assets_dir File.join(root? ? site.site_files_dir : page_dir, page_assets_dir_name) end |
#page_dir ⇒ Object
Directory where the page will be written
68 69 70 71 72 73 74 75 |
# File 'lib/dropsite/site_dir.rb', line 68 def page_dir if root? site.public_dir else pieces = path.sub(/^\//, '').split('/') File.join(site.site_files_dir, *pieces[0..-2]) end end |
#render ⇒ Object
13 14 15 16 |
# File 'lib/dropsite/site_dir.rb', line 13 def render @content = renderer.render(self) dirs.each {|dir| dir.render} end |
#root? ⇒ Boolean
Is this the site root directory?
59 |
# File 'lib/dropsite/site_dir.rb', line 59 def root?; path == '' end |
#size ⇒ Object
The human readable size is blank
65 |
# File 'lib/dropsite/site_dir.rb', line 65 def size; '' end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/dropsite/site_dir.rb', line 85 def to_s "SiteDir(#{is_root? ? 'root' : path})" end |
#write ⇒ Object
Writes the page for this directory, plus any additional files needed by the page.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dropsite/site_dir.rb', line 19 def write if root? index_file = File.join(page_dir, 'index.html') notice "Writing top level index file at #{index_file}" File.open(index_file, 'w') {|f| f.puts content} else # First create the index page index_file = File.join(page_dir, name + '.html') notice "Writing index file for directory #{path} at #{index_file}" File.open(index_file, 'w') {|f| f.puts content} # Create a directory to contain index pages for any child directories Dir.mkdir(File.join(page_dir, name)) end dirs.sort.each{|dir| dir.write} # Determine if the page assets directory is necessary, to avoid clutter writing_page_assets = true begin # Detect whether the write_page_assets method is overridden # In case this explodes in 1.8.6 we'll always create the directory writing_page_assets = renderer.class.instance_method(:write_page_assets).owner != DirRenderer rescue end # The renderer knows what assets are linked to and what needs to be available # to display the page properly if writing_page_assets Dir.mkdir(page_assets_dir) renderer.write_page_assets(self) end end |