Skip to content

Commit

Permalink
Now creating example directories
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalopitz committed Mar 10, 2011
1 parent 2fc1cdb commit a25a6b7
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 26 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ You can define templates, partials and data files.

## Run

Then you can run "genstatic -d ./example" to generate an example website in example/www.
Create an example directory via

genstatic create ./example


Then you can run

genstatic process ./example

to generate the website in example/www.

## Variables inside the page

Expand Down
84 changes: 60 additions & 24 deletions lib/genstatic.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#includes
coffee = require "coffee-script"
path = require "path"
vm = require "vm"
_ = require "underscore"
fs = require "fs"
Expand Down Expand Up @@ -73,27 +74,33 @@ parseDir = (dir, depth) ->
console.log "parsing " + dir

basepath = (i) ->
path = ''
basepath = ''
while i > 0
path += '../'
basepath += '../'
i--

return path
return basepath

handleDir = (filename) ->
filepath = path.normalize dir + '/' + filename
fs.stat filepath, (err, stats) ->
if !err && stats.isFile()
fs.readFile filepath, (err, contents) ->
console.log "compiling file " + filepath.replace dataPath, ''
compile filepath, contents.toString(), basepath depth

if !err && stats.isDirectory()
newdir = filepath.replace dataPath, outPath
fs.mkdir newdir , "777", (err) ->
parseDir (path.normalize filepath), depth + 1


fs.readdir dir, (err, files) ->
for filename in files
do (filename) ->
path = dir + '/' + filename
fs.stat path, (err, stats) ->
if !err && stats.isFile()
fs.readFile path, (err, contents) ->
console.log "compiling file " + path.replace dataPath, ''
compile path, contents.toString(), basepath depth

if !err && stats.isDirectory()
newdir = path.replace dataPath, outPath
fs.mkdir newdir , "777", (err) ->
parseDir (fs.realpathSync path), depth + 1
if err then console.log err.toString()
if files && files.length
for filename in files
do (filename) ->
handleDir filename

# copies the assets into the output folder
copyAssets = () ->
Expand Down Expand Up @@ -128,7 +135,7 @@ process = (dir) ->

checkDir dir, "not a valid directory", (stats) ->

sitePath = rdir = fs.realpathSync dir
sitePath = rdir = path.normalize dir
configPath = rdir + '/config.coffee'

addHelpers()
Expand All @@ -146,10 +153,10 @@ process = (dir) ->
outPath = rdir + '/' + config.output

checkDir templatePath, "not a valid template directory", (stats) ->
templatePath = fs.realpathSync templatePath
templatePath = path.normalize templatePath

checkDir dataPath, "not a valid data directory", (stats) ->
dataPath = fs.realpathSync dataPath
dataPath = path.normalize dataPath

checkDir assetPath, "not a valid asset directory", (stats) ->

Expand All @@ -166,16 +173,45 @@ process = (dir) ->
# clean the config object
config = {}
copyAssets()
outPath = fs.realpathSync outPath
parseDir fs.realpathSync dataPath
outPath = path.normalize outPath
parseDir path.normalize dataPath

create = (dir) ->
console.log "create example structure"
spawn = require('child_process').spawn
cp = spawn 'cp', ['-R', __dirname + '/../example', path.normalize dir]

failed = false

cp.stderr.on 'data', (data) ->
if !failed
console.log ""
console.log "ERROR:"
console.log "creating example structure failed."
console.log "Maybe the containing directory doesn\'t exists?"
failed = true

cp.stderr.end()

cp.stdin.end()

# check if argv is ok
args = require("argsparser").parse()

if !args["-d"]
console.log "Usage: genstatic -d ./site"
if !args["process"] && !args["create"]
console.log ""
console.log "To create a site:"
console.log " genstatic create /path/to/site"
console.log ""
console.log "To process a site:"
console.log " genstatic process /path/to/site"
console.log ""
return

# create an example folder
if args["create"]
create args["create"]

# start to process the directory
process args["-d"]
if args["process"]
process args["process"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "genstatic"
, "description": "A static site generator"
, "keywords": ["static"]
, "version": "0.0.1b"
, "version": "0.0.2b"
, "author": "Pascal Opitz <pascal@ilikecode.co.uk> (http://www.ilikecode.co.uk)"
, "main": "./lib/genstatic"
, "bin": {
Expand Down

0 comments on commit a25a6b7

Please sign in to comment.