Class: Suite::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/suite/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, config, content, view) ⇒ Project

Returns a new instance of Project.



6
7
8
# File 'lib/suite/project.rb', line 6

def initialize path, config, content, view
  @path, @config, @content, @view = path, config, content, view
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/suite/project.rb', line 5

def config
  @config
end

#contentObject

Retrieves the content hash for the current view



15
16
17
# File 'lib/suite/project.rb', line 15

def content
  @content
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/suite/project.rb', line 5

def path
  @path
end

#viewObject

Returns the value of attribute view.



5
6
7
# File 'lib/suite/project.rb', line 5

def view
  @view
end

Instance Method Details

#asset(path) ⇒ Object



42
43
44
# File 'lib/suite/project.rb', line 42

def asset path
  sprocket_environment[path.sub(/javascripts\/|stylesheets\/|images\/|icons\//,'')]
end

#asset_pathObject



50
51
52
# File 'lib/suite/project.rb', line 50

def asset_path
  Suite.env.build? && config["asset_host"] ? config["asset_host"].gsub(/\/$/,'') : "/assets"
end

#asset_registryObject



54
55
56
# File 'lib/suite/project.rb', line 54

def asset_registry
  @_memoized_asset_registry ||= Suite::AssetRegistry.new
end

#file_typesObject



38
39
40
# File 'lib/suite/project.rb', line 38

def file_types
  config["file_types"] || [:html]
end

#include?(slugs) ⇒ Boolean

Returns:



23
24
25
# File 'lib/suite/project.rb', line 23

def include? slugs
  return !!content_at_slugs(slugs)
end

#page_at_slugs(slugs) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/suite/project.rb', line 27

def page_at_slugs slugs
  content_level = pages
  slugs.each do |slug|
    return false unless content_level = content_level[slug.to_s]
  end
  return {
    layout: content_level["layout"] ? content_level["layout"] : content["layout"],
    content: content_level["content"]
  }
end

#pagesObject



19
20
21
# File 'lib/suite/project.rb', line 19

def pages
  content["pages"]
end

#renderersObject

TODO: Puts a renderers config in the yaml to add new renderers



70
71
72
73
74
# File 'lib/suite/project.rb', line 70

def renderers
  @_memoized_render_types ||= begin
    Suite::Renderers.default_renderers
  end
end

#source_asset_pathObject



46
47
48
# File 'lib/suite/project.rb', line 46

def source_asset_path
  path + "/assets"
end

#sprocket_environmentObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/suite/project.rb', line 58

def sprocket_environment
  @_memorized_sprocket_environment ||= begin
    environment = Sprockets::Environment.new
    environment.append_path source_asset_path + '/icons'
    environment.append_path source_asset_path + '/images'
    environment.append_path source_asset_path + '/javascripts'
    environment.append_path source_asset_path + '/stylesheets'
    environment
  end
end