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
#initialize(config) ⇒ Engine
Returns a new instance of Engine.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/awestruct/engine.rb', line 57 def initialize(config) @dir = config.input_dir @config = config @site = Site.new( config ) @site.engine = self @helpers = [] @max_site_mtime = nil adjust_load_path end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
53 54 55 |
# File 'lib/awestruct/engine.rb', line 53 def config @config end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
54 55 56 |
# File 'lib/awestruct/engine.rb', line 54 def dir @dir end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
55 56 57 |
# File 'lib/awestruct/engine.rb', line 55 def site @site end |
Instance Method Details
#create_context(page, content = '') ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/awestruct/engine.rb', line 141 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
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/awestruct/engine.rb', line 92 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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/awestruct/engine.rb', line 77 def generate(profile=nil, base_url=nil, default_base_url=nil, force=false) @base_url = base_url @default_base_url = default_base_url @max_site_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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/awestruct/engine.rb', line 107 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 =~ /\.(asciidoc|adoc)$/ ) page = AsciiDocFile.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 ( path =~ /\.rst$/ ) page = ReStructuredTextFile.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
103 104 105 |
# File 'lib/awestruct/engine.rb', line 103 def load_site_page(relative_path) load_page( File.join( dir, relative_path ) ) end |
#set_urls(pages) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/awestruct/engine.rb', line 169 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
69 70 71 |
# File 'lib/awestruct/engine.rb', line 69 def skin_dir @site.skin_dir end |