Last active
November 15, 2015 11:16
-
-
Save byrichardpowell/928178a11a0ee811f385 to your computer and use it in GitHub Desktop.
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
# project/Gruntfile.coffee | |
# ------------------------ | |
module.exports = (grunt) -> | |
scaffold: | |
component: | |
options: | |
questions: [{ | |
name: 'path' | |
type: 'input' | |
message: 'file path inc filename (e.g: generic/my-component):' | |
filter: (input) -> return input.toLowerCase() | |
validate: (input) -> | |
pattern = new RegExp("^[a-zA-Z0-9\-\/]+$") | |
if pattern.test(input) isnt true | |
return "filepath can contain letters, numbers, dashes and forward slashes only" | |
if input[0] is "/" | |
return "filepath must not start with / (it's relative to /app/coffeescript/views/)" | |
if input[input.length-1] is "/" | |
return "filepath must not end with / (the last part should be the filename)" | |
if input.length <= 3 | |
return "filepath must be longer than 3 characters" | |
return true | |
}, { | |
name: 'displayName' | |
type: 'input' | |
message: 'display name (e.g: MyComponent):' | |
validate: (input) -> | |
pattern = new RegExp("[A-Z]([A-Z0-9]*[a-z][a-z0-9]*[A-Z]|[a-z0-9]*[A-Z][A-Z0-9]*[a-z])[A-Za-z0-9]*") | |
if pattern.test(input) isnt true | |
return "displayName must be CamelCase, not camelCase or camel-case" | |
return true | |
}, { | |
name: 'className' | |
type: 'input' | |
message: 'outer element class-name (e.g: my-component-wrapper):' | |
filter: (input) -> | |
if input[0] is "." | |
input = input.substr(1) | |
return input.toLowerCase() | |
validate: (input) -> | |
pattern = new RegExp("^[a-zA-Z0-9\-]+$") | |
if pattern.test(input) isnt true | |
return "class-name must be class case (e.g: my-awesome-class)" | |
return true | |
}] | |
template: | |
"scaffold/component.csx.coffee": "app/coffeescript/views/{{{path}}}.csx.coffee" | |
"scaffold/style.css": "app/assets/css/{{{path}}}.css" | |
"scaffold/test.csx.coffee": "tests/unit/coffeescript/views/{{{path}}}.csx.coffee" | |
grunt.registerTask "scaffold", [], -> | |
grunt.loadNpmTasks "grunt-scaffold" | |
grunt.task.run "scaffold" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment