Class: Awestruct::Engine
- Inherits:
-
Object
- Object
- Awestruct::Engine
- Defined in:
- lib/awestruct/engine.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #create_context(page, content = '') ⇒ Object
- #find_and_load_site_page(simple_path) ⇒ Object
- #generate(profile = nil, base_url = nil, default_base_url = nil, force = false) ⇒ Object
-
#initialize(config) ⇒ Engine
constructor
A new instance of Engine.
- #load_page(path, options = {}) ⇒ Object
- #load_site_page(relative_path) ⇒ Object
- #set_urls(pages) ⇒ Object
- #skin_dir ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
43 44 45 |
# File 'lib/awestruct/engine.rb', line 43 def config @config end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
44 45 46 |
# File 'lib/awestruct/engine.rb', line 44 def dir @dir end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
45 46 47 |
# File 'lib/awestruct/engine.rb', line 45 def site @site end |
Instance Method Details
#create_context(page, content = '') ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/awestruct/engine.rb', line 122 def create_context(page, content='') context = OpenStruct.new( :site=>site, :content=>content ) context.extend( Awestruct::ContextHelper ) @helpers.each do |h| context.extend( h ) end context.page = page class << context def interpolate_string(str) if site.interpolate str = str || '' str = str.gsub( /\\/, '\\\\\\\\' ) str = str.gsub( /\\\\#/, '\\#' ) str = str.gsub( '@', '\@' ) str = "%@#{str}@" result = instance_eval( str ) result else str || '' end end def evaluate_erb(erb) erb.result( binding ) end end context end |
#find_and_load_site_page(simple_path) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/awestruct/engine.rb', line 77 def find_and_load_site_page(simple_path) path_glob = File.join( config.input_dir, simple_path + '.*' ) candidates = Dir[ path_glob ] return nil if candidates.empty? throw Exception.new( "too many choices for #{simple_path}" ) if candidates.size != 1 dir_pathname = Pathname.new( dir ) path_name = Pathname.new( candidates[0] ) relative_path = path_name.relative_path_from( dir_pathname ).to_s load_page( candidates[0], :relative_path => relative_path ) end |
#generate(profile = nil, base_url = nil, default_base_url = nil, force = false) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/awestruct/engine.rb', line 62 def generate(profile=nil, base_url=nil, default_base_url=nil, force=false) @base_url = base_url @default_base_url = default_base_url @max_yaml_mtime = nil load_site_yaml(profile) load_yamls set_base_url load_layouts load_pages load_extensions set_urls(site.pages) configure_compass generate_files(force) end |
#load_page(path, options = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/awestruct/engine.rb', line 92 def load_page(path, = {}) page = nil if ( [:relative_path].nil? ) #dir_pathname = Pathname.new( dir ) #path_name = Pathname.new( path ) #relative_path = path_name.relative_path_from( dir_pathname ).to_s end fixed_relative_path = ( [:relative_path].nil? ? nil : File.join( '', [:relative_path] ) ) if ( path =~ /\.haml$/ ) page = HamlFile.new( site, path, fixed_relative_path, ) elsif ( path =~ /\.erb$/ ) page = ErbFile.new( site, path, fixed_relative_path, ) elsif ( path =~ /\.textile$/ ) page = TextileFile.new( site, path, fixed_relative_path, ) elsif ( path =~ /\.md$/ ) page = MarkdownFile.new( site, path, fixed_relative_path, ) elsif ( path =~ /\.sass$/ ) page = SassFile.new( site, path, fixed_relative_path, ) elsif ( path =~ /\.scss$/ ) page = ScssFile.new( site, path, fixed_relative_path, ) elsif ( path =~ /\.org$/ ) page = OrgModeFile.new( site, path, fixed_relative_path, ) elsif ( File.file?( path ) ) page = VerbatimFile.new( site, path, fixed_relative_path, ) end page end |
#load_site_page(relative_path) ⇒ Object
88 89 90 |
# File 'lib/awestruct/engine.rb', line 88 def load_site_page(relative_path) load_page( File.join( dir, relative_path ) ) end |
#set_urls(pages) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/awestruct/engine.rb', line 150 def set_urls(pages) pages.each do |page| page_path = page.output_path if ( page_path =~ /^\// ) page.url = page_path else page.url = "/#{page_path}" end if ( page.url =~ /^(.*\/)index.html$/ ) page.url = $1 end end end |
#skin_dir ⇒ Object
58 59 60 |
# File 'lib/awestruct/engine.rb', line 58 def skin_dir @site.skin_dir end |