Created
November 22, 2012 20:18
-
-
Save jonschlinkert/4132781 to your computer and use it in GitHub Desktop.
This is a partial for the alert component. It could be called alert.partial if that was beneficial for some reason.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- partial --> | |
<div class="container"> | |
<h1>alerts</h1> | |
<!-- ko foreach: alerts --> | |
<br> | |
<div data-bind="attr: { class: alertClass }"> | |
<button type="button" class="close" data-dismiss="alert">×</button> | |
<strong data-bind="text: alertType">Warning!</strong> | |
<!-- ko text: message --> | |
Best check yo self, you're not looking too good. | |
<!-- /ko --> | |
</div> | |
<!-- /ko --> | |
</div><!-- /container --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- include partials --> | |
{{> alert}} | |
{{> button}} | |
{{> modal}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global module:false*/ | |
module.exports = function(grunt) { | |
'use strict'; | |
// Project configuration | |
grunt.initConfig({ | |
pkg: '<json:package.json>', | |
meta: { | |
banner: | |
'/**\n' + | |
'* <%= pkg.name %>.js v<%= pkg.version %> by @fat & @mdo\n' + | |
'* Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' + | |
'* http://www.apache.org/licenses/LICENSE-2.0.txt\n' + | |
'*/' | |
}, | |
// Build HTML docs from .mustache files | |
hogan: { | |
partials: { | |
src: 'docs/components/templates/partials/*.mustache', | |
dest: 'docs/components/FILE.html', | |
options: { | |
title: 'Sellside', | |
url: 'docs', | |
setAccount: 'NA', | |
setSiteId: 'NA', | |
layout: 'docs/components/templates/partials/partial.mustache', | |
dev: true, | |
docs: true, | |
app: false, | |
website: false | |
} | |
} | |
} | |
}); | |
// Load npm tasks. | |
grunt.loadNpmTasks('grunt-contrib'); | |
// Load local tasks. | |
grunt.loadTasks('tasks'); | |
grunt.registerTask('default', 'hogan'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Build HTML from mustache files | |
* https://github.com/sellside/ui/grunt.js | |
* | |
* Copyright (c) 2012 Sellside | |
* Authored by Jon Schlinkert | |
*/ | |
module.exports = function(grunt) { | |
// Grunt utilities. | |
var task = grunt.task, | |
file = grunt.file, | |
utils = grunt.util, | |
log = grunt.log, | |
verbose = grunt.verbose, | |
fail = grunt.fail, | |
option = grunt.option, | |
config = grunt.config, | |
template = grunt.template, | |
_ = utils._ | |
// external dependencies | |
var fs = require('fs'), | |
hogan = require('hogan'); | |
// ========================================================================== | |
// TASKS | |
// ========================================================================== | |
grunt.registerMultiTask('hogan', 'Compile mustache files to HTML with hogan.js', function() { | |
var data = this.data, | |
src = grunt.file.expandFiles(this.file.src), | |
dest = grunt.template.process(data.dest), | |
// Options are set in gruntfile | |
defaults = { | |
production: false, | |
docs: false, | |
title: 'Sellside', | |
setAccount: 'NA', | |
setSiteId: 'NA', | |
layout: 'docs/templates/layout.mustache' | |
}, | |
options = _.extend(defaults, this.data.options || {}) | |
!src && grunt.warn('Missing src property.') | |
if(!src) return false | |
!dest && grunt.warn('Missing dest property') | |
if(!dest) return false | |
var done = this.async() | |
var srcFiles = file.expandFiles(src) | |
try { | |
options.layout = fs.readFileSync(options.layout, 'utf8') | |
options.layout = hogan.compile(options.layout, { | |
sectionTags: [{ | |
o: '_i', | |
c: 'i' | |
}] | |
}) | |
} catch(err) { | |
grunt.warn(err) && done(false) | |
return | |
} | |
srcFiles.forEach(function(filepath) { | |
var filename = _.first(filepath.match(/[^\\\/:*?"<>|\r\n]+$/i)).replace(/\.mustache$/, '') | |
grunt.helper('hogan', filepath, filename, options, function(err, result) { | |
err && grunt.warn(err) && done(false) | |
if(err) return | |
file.write(dest.replace('FILE', filename), result) | |
}) | |
}) | |
done() | |
}) | |
// ========================================================================== | |
// HELPERS | |
// ========================================================================== | |
grunt.registerHelper('hogan', function(src, filename, options, callback) { | |
log.writeln('Compiling ' + filename.magenta); | |
var page = fs.readFileSync(src, 'utf8'), | |
html = null, | |
layout = options.layout, | |
context = {}; | |
context[filename] = 'active'; | |
context._i = true; | |
context.production = options.production; | |
context.docs = options.docs; | |
context.setAccount = options.setAccount; | |
context.setSiteId = options.setSiteId; | |
var title = _.template("<%= page == 'Index' ? site : page + ' · ' + site %>") | |
context.title = title({ | |
page: _(filename).humanize().replace('css', 'CSS'), | |
site: options.title | |
}) | |
try { | |
page = hogan.compile(page, { | |
sectionTags: [{ | |
o: '_i', | |
c: 'i' | |
}] | |
}) | |
page = layout.render(context, { | |
body: page | |
}) | |
callback(null, page) | |
} catch(err) { | |
callback(err) | |
return | |
} | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment