Skip to content

Commit

Permalink
updates to how sitefile is executed, new default template
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Jul 3, 2014
1 parent ce04cc5 commit c6bd626
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 37 deletions.
5 changes: 2 additions & 3 deletions bin/sitegen
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ default = {
]==]
sitefile: [==[
require "sitegen"
site = sitegen.create_site =>
sitegen = require "sitegen"
sitegen.create_site =>
@title = $title
site\write!
]==]
}

Expand Down
6 changes: 1 addition & 5 deletions sitegen/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
local Site
do
local _obj_0 = require("sitegen.site")
Site = _obj_0.Site
end
local Site = require("sitegen.site")
local insert
do
local _obj_0 = require("table")
Expand Down
2 changes: 1 addition & 1 deletion sitegen/init.moon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Site from require "sitegen.site"
Site = require "sitegen.site"
import insert from require "table"

default_plugins = {
Expand Down
7 changes: 6 additions & 1 deletion sitegen/site.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ do
if sitefile == nil then
sitefile = nil
end
self.sitefile = sitefile
local SiteFile
do
local _obj_0 = require("sitegen.site_file")
SiteFile = _obj_0.SiteFile
end
self.sitefile = site_file or SiteFile.master
self.io = self.sitefile and self.sitefile.io or io
self.templates = self:Templates(self.config.template_dir)
self.scope = SiteScope(self)
Expand Down
5 changes: 4 additions & 1 deletion sitegen/site.moon
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class Site
write_gitignore: true
}

new: (@sitefile=nil) =>
new: (sitefile=nil) =>
import SiteFile from require "sitegen.site_file"
@sitefile = site_file or SiteFile.master

@io = @sitefile and @sitefile.io or io

@templates = @Templates @config.template_dir
Expand Down
33 changes: 20 additions & 13 deletions sitegen/site_file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,25 @@ do
end,
get_site = function(self)
print(bright_yellow("Using:"), Path.join(self.rel_path, self.name))
local fn = moonscript.loadfile(self.file_path)
local site = nil
local fn = assert(moonscript.loadfile(self.file_path))
local sitegen = require("sitegen")
run_with_scope(fn, {
sitegen = extend({
create_site = function(fn)
site = sitegen.create_site(fn, Site(self))
site.write = function() end
return site
end
}, sitegen)
})
site.write = nil
return site
local old_write = Site.write
local site_ref, site
Site.__base.write = function(site)
site_ref = site
return site
end
do
local old_master = self.__class.master
self.__class.master = self
site = run_with_scope(fn, {
sitegen = require("sitegen")
})
self.__class.master = old_master
end
site = site or temp_site
Site.__base.write = old_write
return assert(site, "Failed to load site from sitefile, make sure site is returned")
end
}
_base_0.__index = _base_0
Expand Down Expand Up @@ -110,6 +115,8 @@ do
end
})
_base_0.__class = _class_0
local self = _class_0
self.master = nil
SiteFile = _class_0
end
return {
Expand Down
37 changes: 24 additions & 13 deletions sitegen/site_file.moon
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import bright_yellow from require "sitegen.output"
-- 1) finds the sitefile, looking up starting from the current dir
-- 2) lets us open files relative to where the sitefile is
class SiteFile
@master: nil -- the global sitefile of the current process

new: (@name="site.moon") =>
dir = lfs.currentdir!
depth = 0
Expand Down Expand Up @@ -70,22 +72,31 @@ class SiteFile
get_site: =>
print bright_yellow"Using:", Path.join @rel_path, @name

fn = moonscript.loadfile @file_path
-- sitefiles have \write! on the bottom, disable it
site = nil
fn = assert moonscript.loadfile @file_path
sitegen = require "sitegen"

run_with_scope fn, {
sitegen: extend {
create_site: (fn) ->
site = sitegen.create_site fn, Site self
site.write = ->
site
}, sitegen
}
-- stub out write to not run during load for legacy
old_write = Site.write

local site_ref, site

Site.__base.write = (site) ->
site_ref = site
site

with old_master = @@master
@@master = @
site = run_with_scope fn, {
-- for legacy pages that doesn't reference module
sitegen: require "sitegen"
}
@@master = old_master

site or= temp_site

Site.__base.write = old_write

site.write = nil -- restore default write
site
assert site, "Failed to load site from sitefile, make sure site is returned"

{
:SiteFile
Expand Down

0 comments on commit c6bd626

Please sign in to comment.