Class: Hobby::Pages::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/hobby/pages.rb

Defined Under Namespace

Classes: Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Directory

Returns a new instance of Directory.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/hobby/pages.rb', line 86

def initialize root
  @root = root

  @sprockets = Sprockets::Environment.new
  @sprockets.append_path "#{root}/js"
  if defined? RailsAssets
    RailsAssets.load_paths.each do |path|
      @sprockets.append_path path
    end
  end

  @pages = Dir["#{root}/html/pages/*.slim"].map do |path|
    page = Page.new path, self
    [page.name, page]
  end.to_h
end

Instance Attribute Details

#sprocketsObject (readonly)

Returns the value of attribute sprockets.



103
104
105
# File 'lib/hobby/pages.rb', line 103

def sprockets
  @sprockets
end

Instance Method Details

#[](name) ⇒ Object



121
122
123
# File 'lib/hobby/pages.rb', line 121

def [] name
  @pages[name]
end

#default_layoutObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/hobby/pages.rb', line 109

def default_layout
  @default_layout ||= begin
    path_to_default_layout = "#{@root}/html/layouts/default.slim"
    if File.exist? path_to_default_layout
      Tilt.new path_to_default_layout
    else
      fail "No layout was found at #{path_to_default_layout}"
    end
  end
end

#to_sObject



105
106
107
# File 'lib/hobby/pages.rb', line 105

def to_s
  @root
end