Class: GallerizeCli::Render::View
- Inherits:
-
Object
- Object
- GallerizeCli::Render::View
- Extended by:
- Forwardable
- Defined in:
- lib/gallerize_cli/render.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
Instance Method Summary collapse
- #current_page ⇒ Object
- #human_folder_name ⇒ Object
- #humanize(string) ⇒ Object
-
#initialize(directory, file_path, locals = {}) ⇒ View
constructor
A new instance of View.
- #render ⇒ Object
- #site_url(path = nil) ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(directory, file_path, locals = {}) ⇒ View
Returns a new instance of View.
34 35 36 37 38 |
# File 'lib/gallerize_cli/render.rb', line 34 def initialize(directory, file_path, locals={}) @directory = directory @file_path = file_path @locals = locals end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
30 31 32 |
# File 'lib/gallerize_cli/render.rb', line 30 def directory @directory end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
30 31 32 |
# File 'lib/gallerize_cli/render.rb', line 30 def file_path @file_path end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
30 31 32 |
# File 'lib/gallerize_cli/render.rb', line 30 def locals @locals end |
Instance Method Details
#current_page ⇒ Object
57 58 59 |
# File 'lib/gallerize_cli/render.rb', line 57 def current_page (locals[:page_index] + 1 / directory.config.images_per_page) end |
#human_folder_name ⇒ Object
40 41 42 |
# File 'lib/gallerize_cli/render.rb', line 40 def human_folder_name humanize(File.basename(File.('.'))) end |
#humanize(string) ⇒ Object
44 45 46 |
# File 'lib/gallerize_cli/render.rb', line 44 def humanize(string) string.to_s.gsub(/[-_]+/, ' ').split(' ').collect(&:capitalize).join(' ') end |
#render ⇒ Object
48 49 50 51 |
# File 'lib/gallerize_cli/render.rb', line 48 def render GallerizeCli.logger.debug("generate #{file_path}") File.write(file_path, Haml::Engine.new(template).render(self, locals)) end |
#site_url(path = nil) ⇒ Object
53 54 55 |
# File 'lib/gallerize_cli/render.rb', line 53 def site_url(path=nil) File.join(config.site_url, path) end |
#total_pages ⇒ Object
61 62 63 |
# File 'lib/gallerize_cli/render.rb', line 61 def total_pages directory.total_images_count / directory.config.images_per_page end |