Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
NotificationsYou must be signed in to change notification settings

camplight/expressSite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

"Addon" nodejs module for expressjs framework providing lightweight 'pages' support, or other called client-side app single-page apps.

Includes:

  • packageme (https://github.com/camplight/packageme/) for packaging directories of files needed by client-side apps
  • Backbone-like class implementation of client-side app (a Page).
  • consolidate.js for server-side template engines

Usage

add "expressSite" to dependencies in package.jsonadd your prefered template engine, for example "jade" to dependencies in package.jsonadd "consolidate" to dependencies in package.json

Createapp.js with the following example code:

var app = require("expressSite");var cons = require("consolidate");app.engine('jade', cons.jade);app.set('view engine', 'jade');app.configure(function(){  app.useExpressSiteMiddleware();});app.addPage({  url: "/",  content: "./templates/index",  variables: {    title: "Index Page"  }});app.listen(8000, function(){  console.log("listening on 8000");});

Createclient andclient/templates folders.

Place your layout template containing these as minimum at/client/templates/layout.jade:

!!! htmlhead  !{javascripts}  !{stylesheets}body  !{views}  !{content}

{javascripts},{stylesheets} &{views} will be replaced by expressSite with appropiate path to packaged javascripts, stylesheets & views.{content} will be replaced with the content of the pages using that layout.

Create/client/templates/index.jade file with content as you like.

Launch the application or refer to the demo for additional usage examples.

Reference

expressSite

  • addPage(Page Class orPage attributes object)

Note that Page attributes which are Array(views,style,code) or Object(variables) and are present indefaultPageAtrributes will be appened/merged with thedefaultPageAttributes. HoweverPage.defaults will override those arrays/objects.

Page

var Page = require("expressSite/Page");var MyPage = module.exports = Page.extend({  // attributes  defaults: {    name: String,    root: String,    url: String,    code: Array[String],    views: Array[String],    viewsEngine: String,    style: Array[String],    content: String,    variables: Object  },  extendDefaults: {    views: Array[String],    code: Array[String],    ...  }});

attributes

Note that all paths exceptroot can be full or relative(starting with./,../ or without/), in case of relative usage,root value will be prepended.

extendDefaults object if present will override primitive variables and append(push at the end) to arrays for defaults.example:

var MyPage = Page.extend({  defaults : {    variable: "A",    list: [1, 2]  },  extendDefaults : {    variable: "B",    list: [3]  }});var p = new MyPage();console.log(p.attributes.variable); // output: Bconsole.log(p.attributes.list); // output: [1,2,3]
  • url -> uri to whichexpressSite.addPage should mount given page, if missingaddPage won't mount the page in express router.

  • name -> Page's name, value used when generating code & style tags otherwise self generated unique names will be in place.

  • root -> full path to page's assets (code, styles, templates, views), if missing content/body parent directory will be used as root.

  • content -> path to template file to be rendered /must be provided/

  • layout -> path to template file to be used as layout, if missing only the content/body will be rendered and send as response.

  • code -> path or array of paths to page's code/javascripts/coffeescript & etc. It is mainly been passed directly topackageme.Page.renderCode(app) is magically used byexpressSite.addPage to register route handler for those code assets.

  • style -> path or array of paths to page's stylesheets. It is again send directly topackageme. And there isPage.renderStyle(app) for providing packaged version of those assets.

  • views -> array of paths to page's client-side templates. Folders or Files whichpackageme will combine and inject to the page's content withinviews local variable. Those views/templates can be used within browser and as such to minify client requests to the site.

  • viewsEngine -> string, defaults to "html", can be set to 'jade' which instructs packageme to compile jade views to html instead

  • variables -> object of variables which will be used as data source when rendering the page's templated content.

Page.initialize(attributes, options)

Page.registerStyleHandlers(app)

Page.registerCodeHandlers(app)

Page.compileViews(callback)

Page.compileCode(callback)

Page.compileStyle(callback)

Page.render(req, res, next)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp