Skip to content
Permalink
Browse files

feat(option): add angular.ngFormify option

  • Loading branch information
jyounce committed Aug 4, 2015
1 parent 0106b68 commit 876df59687e78da5491201c4f85eee64c894b8d4
@@ -125,6 +125,7 @@ gulp rapid-build:test:prod
# angular.templateCache.dev = (boolean) defaults to false = use template cache when running default and dev task
# angular.templateCache.urlPrefix = (string) prefix for template urls
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false = prefix template urls with a '/'
# angular.ngFormify = (boolean) defaults to false = set to true to replace all html form tags with ng:form in client dist, useful if your application is going to be wrapped in a global form
# spa.title = (string) defaults to package.json name or 'Application' = html title tag value
# spa.description = (string) defaults to package.json description = html meta description tag value
# spa.src.filePath = (string) set if you want to use your own spa file and not the build system's (file must be located in your client src directory)
@@ -12,6 +12,10 @@ module.exports = (config, options) ->
# ============
angular = {}

# ng-formify
# ==========
angular.ngFormify = options.angular.ngFormify or false

# httpBackend
# ===========
httpBackendDir = options.angular.httpBackend.dir or 'mocks'
@@ -40,6 +40,7 @@ module.exports = (config, options) ->
options.angular.modules = null if not isType.array options.angular.modules
options.angular.version = null if not isType.string options.angular.version
options.angular.moduleName = null if not isType.string options.angular.moduleName
options.angular.ngFormify = null if not isType.boolean options.angular.ngFormify
options.angular.httpBackend = {} if not isType.object options.angular.httpBackend
options.angular.httpBackend.dev = null if not isType.boolean options.angular.httpBackend.dev
options.angular.httpBackend.prod = null if not isType.boolean options.angular.httpBackend.prod
@@ -6,6 +6,7 @@ module.exports = (config, rbDir) ->
app: process.cwd()
config: "#{rbDir}/config"
files: "#{rbDir}/files"
plugins: "#{rbDir}/plugins"
helpers: "#{rbDir}/helpers"
init: "#{rbDir}/init"
tasks: "#{rbDir}/tasks"
@@ -52,6 +52,7 @@
"gulp-sequence": "~0.4.0",
"gulp-template": "~3.0.0",
"gulp-uglify": "~1.2.0",
"gulp-util": "~3.0.6",
"gulp-watch": "~4.3.4",
"jasmine-core": "~2.3.4",
"karma": "~0.13.3",
@@ -65,7 +66,8 @@
"less-imports": "~1.1.0",
"mkdirp": "~0.5.1",
"open": "~0.0.5",
"q": "~1.4.1"
"q": "~1.4.1",
"through2": "~2.0.0"
},
"keywords": [
"build system",
@@ -0,0 +1,32 @@
PLUGIN_NAME = 'gulp-ng-formify'
through = require 'through2'
gutil = require 'gulp-util'
PluginError = gutil.PluginErrors

# For find and replace
# ====================
openTagRegEx = new RegExp '<\\s*\\bform', 'gm'
closeTagRegEx = new RegExp '<\\s*/\\s*\\bform', 'gm'
openTag = '<ng:form'
closeTag = '</ng:form'

# Helpers
# =======
ngFormify = (contents) ->
contents.replace openTagRegEx, openTag
.replace closeTagRegEx, closeTag

# Plugin level function(dealing with files)
# =========================================
gulpNgFormify = ->
through.obj (file, enc, cb) ->
return cb null, file if file.isNull() # return empty file
return cb new PluginError PLUGIN_NAME, 'streaming not supported' if file.isStream()

if file.isBuffer()
contents = ngFormify file.contents.toString()
file.contents = new Buffer contents

cb null, file

module.exports = gulpNgFormify
@@ -1,11 +1,15 @@
module.exports = (gulp, config, watchFile={}) ->
q = require 'q'
gulpif = require 'gulp-if'
tasks = require("#{config.req.helpers}/tasks")()
ngFormify = require "#{config.req.plugins}/gulp-ng-formify"
runNgFormify = config.angular.ngFormify
forWatchFile = !!watchFile.path

runTask = (src, dest) ->
defer = q.defer()
gulp.src src
.pipe gulpif runNgFormify, ngFormify()
.pipe gulp.dest dest
.on 'end', ->
# console.log dest
@@ -5,6 +5,8 @@ module.exports = (gulp, config, watchFile={}) ->
gulpif = require 'gulp-if'
minifyHtml = require 'gulp-minify-html'
templateCache = require 'gulp-angular-templatecache'
ngFormify = require "#{config.req.plugins}/gulp-ng-formify"
runNgFormify = config.angular.ngFormify
forWatchFile = !!watchFile.path

# globs
@@ -54,6 +56,7 @@ module.exports = (gulp, config, watchFile={}) ->
gulp.src src
.pipe addToDistPath()
.pipe gulpif minify, minifyHtml minOpts
.pipe gulpif runNgFormify, ngFormify()
.pipe templateCache file, opts
.pipe gulp.dest dest
.on 'end', ->

0 comments on commit 876df59

Please sign in to comment.
You can’t perform that action at this time.