Permalink
Browse files

Moved stylus generation outside of stitch

  • Loading branch information...
1 parent 8b5293c commit 580bffce8f6e7b07c521d48941f10fe3141d90a9 @trabianmatt trabianmatt committed Jan 22, 2013
View
@@ -7,8 +7,12 @@ for _task, func of titanium.tasks
task "t:#{_task}", -> func pkg
task "build", ->
+ invoke "t:build:styles"
invoke "t:bootstrap"
invoke "t:build"
task "build:test", ->
invoke "t:build:test"
+
+task "build:styles", ->
+ invoke "t:build:styles"
View
@@ -10,7 +10,7 @@ printWarn = (line) -> process.stderr.write line + '\n'
printIt = (buffer) -> printLine buffer.toString().trim()
-stylusConverter = require './converter/stylus'
+styles = require './styles'
titaniumPath = "node_modules/.bin/titanium"
@@ -86,15 +86,7 @@ module.exports =
load: (root, pkg) ->
- options = _({}).extend pkg,
- compilers:
- styl: (module, filename) ->
- source = fs.readFileSync(filename, 'utf8')
- source = stylusConverter.convert source
- source = "module.exports = #{JSON.stringify source};"
- module._compile(source, filename)
-
- buildTasks = require('stitch-up').load(root, options).tasks
+ buildTasks = require('stitch-up').load(root, pkg).tasks
runSimulator = (callback) ->
@@ -123,15 +115,21 @@ module.exports =
"build:test": ->
buildTasks.test()
+ "build:styles": ->
+ styles.build pkg
+
"iphone:run": ->
bootstrap pkg
runAndWatch (callback) ->
console.warn 'build tasks'
- buildTasks.stitch ->
- console.warn 'run simulator'
- runSimulator callback
+
+ styles.build pkg, ->
+
+ buildTasks.stitch ->
+ console.warn 'run simulator'
+ runSimulator callback
"iphone:run:nobuild": ->
@@ -66,6 +66,16 @@ compiler.prototype.visitProperty = (prop) ->
module.exports =
+ convertRenderer: (stylusWrapper, callback) ->
+
+ output = undefined
+
+ compiler.prototype.styles = {}
+
+ stylusWrapper.render (err) ->
+ output = compiler.prototype.styles
+ callback? err, output
+
convert: (input, callback) ->
output = undefined
View
@@ -0,0 +1,32 @@
+fs = require 'fs'
+stylus = require 'stylus'
+
+converter = require './converter'
+
+module.exports =
+
+ build: (options, callback) ->
+
+ if config = options.stylus
+
+ fs.readFile config.main, 'utf8', (err, source) ->
+
+ renderer = stylus(source)
+ .set 'paths', config.paths
+
+ if plugins = config.plugins
+
+ for plugin in config.plugins
+ if loadStyles = require(plugin)?.loadStyles
+ renderer.use loadStyles
+
+ converter.convertRenderer renderer, (err, out) ->
+ fs.writeFile config.output, "STYLES = #{JSON.stringify(out, null, ' ')};", (err) ->
+
+ if err
+ console.warn 'err', err if err
+ else
+ console.log "Compiled #{options.stylus.output}"
+
+ callback?()
+
View
@@ -40,6 +40,14 @@
"email": "matt@trabian.com"
},
"main": "./lib/index.coffee",
+ "stylus": {
+ "output": "Resources/styles.js",
+ "paths": [ "styles" ],
+ "plugins": [
+ "titanium-backbone-ks"
+ ],
+ "main": "styles/main.styl"
+ },
"stitch": {
"identifier":"stitchRequire",
"output":
View
@@ -0,0 +1 @@
+@import 'ks'
View
@@ -0,0 +1,19 @@
+View
+
+ &.wrapper
+ layout vertical
+ top 11
+ right 11
+ left 11
+
+ &.horizontal
+ width unquote('Ti.UI.FILL')
+ height 44
+ layout horizontal
+ Button
+ width 50%
+
+TextField
+ width unquote('Ti.UI.FILL')
+ height 44
+ borderStyle unquote('Ti.UI.INPUT_BORDERSTYLE_ROUNDED')
View
@@ -0,0 +1,12 @@
+Label
+ left 0
+ width 100%
+ color rgba(#333, 0.8)
+ bottom 11
+ &.heading
+ font 18 bold
+ &.reversed-name
+ color #030
+ &.error
+ color #f00 !important
+
@@ -20,7 +20,7 @@ _ = require 'underscore'
{ assert } = helpers.chai
-converter = require '../../lib/converter/stylus'
+converter = require '../../lib/styles/converter'
ti = helpers.require 'tb/lib/ti'
@@ -118,22 +118,3 @@ describe 'The stylus converter', ->
assert.isTrue errorNode.rules.color.important
done()
-
- it 'should be supported by stitch', ->
-
- styles = helpers.require 'fixtures/styles'
-
- assert.ok styles
-
- Label = styles.Label
-
- assert.ok Label
- assert.equal Label.rules?.color, '#333'
-
- assert.ok Label.selectors
-
- selectorNode = Label.selectors[0]
-
- assert.equal selectorNode.selector, 'Window Label'
- assert.equal selectorNode.rules?.height, 50
-

0 comments on commit 580bffc

Please sign in to comment.