Class: GallerizeCli::Render::View

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gallerize_cli/render.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#directoryObject (readonly)

Returns the value of attribute directory.



30
31
32
# File 'lib/gallerize_cli/render.rb', line 30

def directory
  @directory
end

#file_pathObject (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

#localsObject (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_pageObject



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_nameObject



40
41
42
# File 'lib/gallerize_cli/render.rb', line 40

def human_folder_name
  humanize(File.basename(File.expand_path('.')))
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

#renderObject



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_pagesObject



61
62
63
# File 'lib/gallerize_cli/render.rb', line 61

def total_pages
  directory.total_images_count / directory.config.images_per_page
end