shuriken 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,104 +1,108 @@
1
- # First off, add our dataAttr extensions.
2
- if jQuery?
3
- (($) ->
4
- stringToDataKey: (key) -> "data-$key".replace /_/g, '-'
5
- $.fn.dataAttr: (key, value) -> @attr stringToDataKey(key), value
6
- $.fn.removeDataAttr: (key) -> @removeAttr stringToDataKey(key)
7
- $.fn.hasDataAttr: (key) -> @is "[${stringToDataKey(key)}]"
8
- $.metaAttr: (key) -> $("meta[name='$key']").attr "content"
9
- )(jQuery)
10
-
1
+ (->
2
+
3
+ # First off, add our dataAttr extensions.
4
+ if jQuery?
5
+ (($) ->
6
+ stringToDataKey: (key) -> "data-$key".replace /_/g, '-'
7
+ $.fn.dataAttr: (key, value) -> @attr stringToDataKey(key), value
8
+ $.fn.removeDataAttr: (key) -> @removeAttr stringToDataKey(key)
9
+ $.fn.hasDataAttr: (key) -> @is "[${stringToDataKey(key)}]"
10
+ $.metaAttr: (key) -> $("meta[name='$key']").attr "content"
11
+ )(jQuery)
11
12
 
12
- Shuriken: {
13
- Base: {}
14
- Util: {}
15
- jsPathPrefix: "/javascripts/"
16
- jsPathSuffix: ""
17
- namespaces: {}
18
- extensions: []
19
- }
20
13
 
21
- Shuriken.Util.underscoreize: (s) ->
22
- s.replace(/\./g, '/').replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/-/g, '_').toLowerCase()
14
+ Shuriken: {
15
+ Base: {}
16
+ Util: {}
17
+ jsPathPrefix: "/javascripts/"
18
+ jsPathSuffix: ""
19
+ namespaces: {}
20
+ extensions: []
21
+ }
23
22
 
24
- Shuriken.Util.scopedClosure: (closure, scope) ->
25
- closure.call scope, scope if $.isFunction closure
23
+ Shuriken.Util.underscoreize: (s) ->
24
+ s.replace(/\./g, '/').replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/-/g, '_').toLowerCase()
26
25
 
26
+ scopedClosure: (closure, scope) ->
27
+ closure.call scope, scope if $.isFunction closure
27
28
 
28
- # Base is the prototype for all namespaces.
29
- base: Shuriken.Base
29
+ # Base is the prototype for all namespaces.
30
+ base: Shuriken.Base
30
31
 
31
- base.hasChildNamespace: (child) ->
32
- @children.push child
32
+ base.hasChildNamespace: (child) ->
33
+ @children.push child
33
34
 
34
- base.toNSName: (children...) ->
35
- parts: children
36
- current: @
37
- while current.parent?
38
- parts.unshift parts
39
- current: current.parent
40
- parts.join "."
35
+ base.toNSName: (children...) ->
36
+ parts: children
37
+ current: @
38
+ while current.parent?
39
+ parts.unshift parts
40
+ current: current.parent
41
+ parts.join "."
41
42
 
42
- base.getNS: (namespace) ->
43
- parts: key.split "."
44
- currentNS: @
45
- for name in parts
46
- return unless currentNS[name]?
47
- currentNS: currentNS[name]
48
- currentNS
43
+ base.getNS: (namespace) ->
44
+ parts: key.split "."
45
+ currentNS: @
46
+ for name in parts
47
+ return unless currentNS[name]?
48
+ currentNS: currentNS[name]
49
+ currentNS
49
50
 
50
- base.getRootNS: ->
51
- current: @
52
- current: current.parent while current.parent?
53
- current
51
+ base.getRootNS: ->
52
+ current: @
53
+ current: current.parent while current.parent?
54
+ current
54
55
 
55
- base.hasNS: (namespace) ->
56
- @getNS(namespace)?
56
+ base.hasNS: (namespace) ->
57
+ @getNS(namespace)?
57
58
 
58
- base.withNS: (key, initializer) ->
59
- parts: key.split "."
60
- currentNS: @
61
- for name in parts
62
- currentNS[name]: makeNS(name, currentNS, @baseNS) if not currentNS[name]?
63
- currentNS: currentNS[name]
64
- hadSetup: $.isFunction currentNS.setup
65
- Shuriken.Util.scopedClosure initializer, currentNS
66
- currentNS.setupVia currentNS.setup if not hadSetup and $.isFunction currentNS.setup
67
- currentNS
59
+ base.withNS: (key, initializer) ->
60
+ parts: key.split "."
61
+ currentNS: @
62
+ for name in parts
63
+ currentNS[name]: makeNS(name, currentNS, @baseNS) if not currentNS[name]?
64
+ currentNS: currentNS[name]
65
+ hadSetup: $.isFunction currentNS.setup
66
+ scopedClosure initializer, currentNS
67
+ currentNS.setupVia currentNS.setup if not hadSetup and $.isFunction currentNS.setup
68
+ currentNS
68
69
 
69
- base.withBase: (closure) ->
70
- Shuriken.Util.scopedClosure closure, @baseNS
70
+ base.withBase: (closure) ->
71
+ scopedClosure closure, @baseNS
72
+
73
+ base.extend: (closure) ->
74
+ scopedClosure closure, @
71
75
 
72
- base.isRoot: ->
73
- not @parent?
76
+ base.isRoot: ->
77
+ not @parent?
74
78
 
75
- base.log: (args...) ->
76
- console.log "[${@toNSName()}]", args...
79
+ base.log: (args...) ->
80
+ console.log "[${@toNSName()}]", args...
77
81
 
78
- base.debug: (args...) ->
79
- console.log "[Debug - ${@toNSName()}]", args...
82
+ base.debug: (args...) ->
83
+ console.log "[Debug - ${@toNSName()}]", args...
80
84
 
81
- base.setupVia: (f) ->
82
- $(document).ready => Shuriken.Util.scopedClosure(f, @) if @autosetup?
85
+ base.setupVia: (f) ->
86
+ $(document).ready => scopedClosure(f, @) if @autosetup?
83
87
 
84
- base.require: (key, callback) ->
85
- ns: @getNS key
86
- if ns?
87
- Shuriken.Util.scopedClosure callback, ns
88
- else
89
- path: Shuriken.Util.underscoreize "${@toNSName()}.$key"
90
- url: "${Shuriken.jsPathPrefix}${path}.js${Shuriken.jsPathSuffix}"
91
- script: $ "<script />", {type: "text/javascript", src: url}
92
- script.load -> Shuriken.Util.scopedClosure callback, @getNS(key)
93
- script.appendTo $ "head"
88
+ base.require: (key, callback) ->
89
+ ns: @getNS key
90
+ if ns?
91
+ scopedClosure callback, ns
92
+ else
93
+ path: Shuriken.Util.underscoreize "${@toNSName()}.$key"
94
+ url: "${Shuriken.jsPathPrefix}${path}.js${Shuriken.jsPathSuffix}"
95
+ script: $ "<script />", {type: "text/javascript", src: url}
96
+ script.load -> scopedClosure callback, @getNS(key)
97
+ script.appendTo $ "head"
94
98
 
95
- base.autosetup: true
99
+ base.autosetup: true
96
100
 
97
- # Used as a part of the prototype chain.
98
- Shuriken.Namespace: ->
99
- Shuriken.Namespace.prototype: Shuriken.Base
101
+ # Used as a part of the prototype chain.
102
+ Shuriken.Namespace: ->
103
+ Shuriken.Namespace.prototype: Shuriken.Base
100
104
 
101
- makeNS: (name, parent, sharedPrototype) ->
105
+ makeNS: (name, parent, sharedPrototype) ->
102
106
  sharedPrototype?= new Shuriken.Namespace()
103
107
  namespace: ->
104
108
  @name: name
@@ -107,21 +111,23 @@ makeNS: (name, parent, sharedPrototype) ->
107
111
  @children: []
108
112
  parent.hasChildNamespace(@) if parent?
109
113
  @
110
- namespace.prototype: sharedPrototype
111
- new namespace name, parent
112
-
113
- Shuriken.defineExtension: (closure) ->
114
- for namespace in Shuriken.namespaces
115
- console.log namespace
116
- Shuriken.Util.scopedClosure closure, namespace
117
- Shuriken.extensions.push closure
114
+ namespace.prototype: sharedPrototype
115
+ new namespace name, parent
116
+
117
+ Shuriken.defineExtension: (closure) ->
118
+ for namespace in Shuriken.namespaces
119
+ console.log namespace
120
+ scopedClosure closure, namespace
121
+ Shuriken.extensions.push closure
118
122
 
119
- Shuriken.as: (name) ->
120
- ns: makeNS name
121
- Shuriken.namespaces[name]: ns
122
- Shuriken.root[name]: ns
123
- Shuriken.Util.scopedClosure extension, ns for extension in Shuriken.extensions
124
- ns
123
+ Shuriken.as: (name) ->
124
+ ns: makeNS name
125
+ Shuriken.namespaces[name]: ns
126
+ Shuriken.root[name]: ns
127
+ scopedClosure extension, ns for extension in Shuriken.extensions
128
+ ns
125
129
 
126
- Shuriken.root: @
127
- @['Shuriken']: Shuriken
130
+ Shuriken.root: @
131
+ @['Shuriken']: Shuriken
132
+
133
+ )()
data/lib/shuriken.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Shuriken
2
2
 
3
- VERSION = "0.1.1".freeze
3
+ VERSION = "0.1.2".freeze
4
4
 
5
5
  def self.register_framework!
6
6
  Barista::Framework.register 'shuriken', File.expand_path('../coffeescripts', File.dirname(__FILE__))
data/shuriken.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shuriken}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Darcy Laycock"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Darcy Laycock