Permalink
Browse files

* add settings, update docs, bump version

  • Loading branch information...
1 parent c97596a commit afc04ef79cdd04b1223d2d27704ac0250c5a999d @Meettya committed Mar 14, 2013
Showing with 69 additions and 20 deletions.
  1. +6 −0 History.md
  2. +5 −2 README.md
  3. +4 −1 README_ru.md
  4. +1 −1 Roadmap.md
  5. +1 −1 package.json
  6. +18 −12 src/app.coffee
  7. +11 −2 src/packer.coffee
  8. +23 −1 test/test_app.coffee
View
6 History.md
@@ -1,3 +1,9 @@
+## 0.2.3 / 2013/03-15 01:00 AM
+
+ - Add settings to Clinch constructor - 'jade', 'strict', 'inject'
+ - Huge refactor to DiC
+ - Update docs
+
## 0.2.1 / 2013/03-05 02:00 PM
- Fix 'replacement' and 'exclude' - now its just string comparisons
View
7 README.md
@@ -9,7 +9,7 @@ YA ComonJS to browser packer tool, well-suited for tiny widgets by small overhea
- `.json` - wrap in `module.exports` as node do it on `require('file.json')`
- `.coffee` - compile to JavaScript
- `.eco` - precompile to JavaScript function
- - `.jade` - precompile it to [client-mode](https://github.com/visionmedia/jade#a4) way
+ - `.jade` - precompile it in [client-mode](https://github.com/visionmedia/jade#a4) way
### More about .jade
@@ -103,7 +103,10 @@ This method will force flush packer cache. As usually **clinch** flush cache if
###
From v 2.0.3 Clinch support some settings
###
- log : off
+
+ log : off # will add verbose output, but now not realized yet
+ strict : on # knob for 'use strict;' in bundle header
+ inject : on # if changed to 'off' - bundle will not to inject 'package_name' to global
###
this settings will be applied to jade.compile() function
View
5 README_ru.md
@@ -137,7 +137,10 @@
###
С версии 2.0.3 Clinch поддерживает некоторые настройки
###
- log : off
+
+ log : off # включает отладочную информацию, пока не реализовано
+ strict : on # управляет строчкой 'use strict;' в шапке бандла
+ inject : on # если изменить на 'off' - бандл не будет инжектить 'package_name' в глобальную переменную.
###
эти настройки могут быть переданы функции jade.compile()
View
2 Roadmap.md
@@ -1,5 +1,5 @@
## Roadmap for clinch
- Replace detective with self-writed class on acorn
-- Add jade support
+- Add jade support - done
- Add more tests
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "clinch",
- "version": "0.2.1",
+ "version": "0.2.3",
"description": "YA ComonJS to browser packer tool, well-suited for widgets by small overhead and big app by smart settings",
"main": "./src/app.coffee",
"scripts": {
View
30 src/app.coffee
@@ -30,25 +30,31 @@ class Clinch
###
This internal method used to configure components in DiC
###
-
- ###
- jade =
- pretty : on
- self : on
- compileDebug : off
-
- clinch_obj = new Clinch {jade, log : on}
-
- ###
_configureComponents : ->
-
# just use short-cut
log = !!@_options_.log
- # set jade compiler settings
+ ###
+ set jade compiler settings for jade.compile()
+ jade =
+ pretty : on
+ self : on
+ compileDebug : off
+ ###
if jade = @_options_.jade
@_dic_obj_.setComponentsSettings FileProcessor : {jade, log}
+ ###
+ set packer settings
+ strict : on
+ inject : on
+ ###
+ packer_settings = {log}
+ for setting_name in ['strict', 'inject']
+ if @_options_[setting_name]?
+ packer_settings[setting_name] = @_options_[setting_name]
+ @_dic_obj_.setComponentsSettings Packer : packer_settings
+
null
View
13 src/packer.coffee
@@ -13,6 +13,10 @@ class Packer
# for debugging
@_do_logging_ = if @_options_.log? and @_options_.log is on and console?.log? then yes else no
+ @_settings_ =
+ strict : @_options_.strict ? on
+ inject : @_options_.inject ? on
+
###
This method create browser package with given cofiguration
###
@@ -32,7 +36,9 @@ class Packer
# prepare environment
[ env_header, env_body ] = @_buildEnvironment package_code.environment_list, package_code.members
- result = "(function() {\n 'use strict';\n" +
+ strict_str = if @_settings_.strict then '\n \'use strict\';' else ''
+
+ result = "(function() {#{strict_str}\n" +
env_header +
@_getHeader() +
"\n dependencies = #{JSON.stringify package_code.dependencies_tree};\n"
@@ -50,7 +56,10 @@ class Packer
result += env_body
# add bundle export
- result += "\n/* bundle export */\nthis.#{package_name} = {\n"
+
+ var_prefix = if @_settings_.inject then 'this.' else 'var '
+
+ result += "\n/* bundle export */\n#{var_prefix}#{package_name} = {\n"
bundle_index = 0
for bundle_name in package_code.bundle_list
result += if bundle_index++ is 0 then "" else ",\n"
View
24 test/test_app.coffee
@@ -21,7 +21,7 @@ describe 'Clinch app itself:', ->
jade =
pretty : off
- clinch_obj = new Clinch {jade}
+ clinch_obj = new Clinch {jade, strict : off}
describe 'buldPackage()', ->
@@ -52,6 +52,8 @@ describe 'Clinch app itself:', ->
res_fn = (err, code) ->
expect(err).to.be.null
+ # console.log code
+
# this is browser emulation
vm.runInNewContext code, jade_sandbox
{JadePowered} = jade_sandbox.my_package
@@ -72,4 +74,24 @@ describe 'Clinch app itself:', ->
expect(clinch_obj.flushCache()).to.be.null
+ describe 'constructor options', ->
+
+ it 'should supress injection on "inject : off" ', (done) ->
+
+ clinch_obj = new Clinch {inject : off}
+
+ package_config =
+ bundle :
+ JadePowered : fixturesJade
+ replacement :
+ fs : fixturesWebShims + '/noops'
+ jade : fixturesWebShims + '/noops'
+
+ res_fn = (err, code) ->
+ expect(err).to.be.null
+ vm.runInNewContext code, jade_sandbox = {}
+ jade_sandbox.should.not.to.contain.keys 'my_package'
+ done()
+
+ clinch_obj.buldPackage 'my_package', package_config, res_fn

0 comments on commit afc04ef

Please sign in to comment.