Module: Edison
- Defined in:
- lib/edison.rb,
lib/edison.rb
Defined Under Namespace
Modules: Helpers, YAMLFrontMatter Classes: ModelsLoader, Renderer, Router, StaticFileHandler
Constant Summary collapse
- VERSION =
"0.0.3"
Class Attribute Summary collapse
-
.models ⇒ Object
readonly
Returns the value of attribute models.
-
.renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
.routes ⇒ Object
readonly
Returns the value of attribute routes.
Class Method Summary collapse
Class Attribute Details
.models ⇒ Object (readonly)
Returns the value of attribute models.
148 149 150 |
# File 'lib/edison.rb', line 148 def models @models end |
.renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
148 149 150 |
# File 'lib/edison.rb', line 148 def renderer @renderer end |
.routes ⇒ Object (readonly)
Returns the value of attribute routes.
148 149 150 |
# File 'lib/edison.rb', line 148 def routes @routes end |
Class Method Details
.config(&b) ⇒ Object
172 173 174 |
# File 'lib/edison.rb', line 172 def self.config(&b) instance_eval &b end |
.generate! ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/edison.rb', line 175 def self.generate! renderer = Renderer.new(@views) site = File.join(@directory, "_site") FileUtils.rm_rf(site) Dir.mkdir(site) puts "Copying static files..." routes.static.each do |name| src = File.join(@directory, name) dest = File.join(site, name) FileUtils.mkdir_p File.dirname(dest) FileUtils.copy src, dest end routes.urls.each do |(url, view_name, data)| puts "Creating /#{url}..." fname = File.join(site, url) FileUtils.mkdir_p(File.dirname(fname)) File.open(fname, "w") do |f| f.write renderer.render(view_name, data) end end end |
.initialize!(directory) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/edison.rb', line 150 def self.initialize!(directory) @directory = directory @routes = Router.new loader = ModelsLoader.new @models = loader.load(File.join(directory, "_models")) @views = Hash[Dir[File.join(directory, "_views", "*")].map do |fname| puts "Loading view _views/#{File.basename(fname)}..." name = File.basename(fname).sub(/\.[^\.]+$/,'') data = Hashie::Mash.new Edison::YAMLFrontMatter.read(fname) [name, data] end] static = StaticFileHandler.load(directory) static.possibly_dynamic.each do |(url, data)| @routes.url url, url, data @views[url] = data end static.just_copy.each &@routes.method(:copy) end |