stylus_assets 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -94,6 +94,16 @@ StylusAssets::StylusTemplate.name_filter = lambda { |n| n.sub /^(templates|style
94
94
 
95
95
  By default, `name_filter` strips the leading `templates/`, `stylesheets/` and `styles/` directory off of the name.
96
96
 
97
+ #### Variable prefix
98
+
99
+ By default, Stylus assets doesn't prefix the style variables with a `$`, but you can configure it to do so:
100
+
101
+ ```ruby
102
+ StylusAssets::StylusTemplate.variable_prefix = true
103
+ ```
104
+
105
+ All following examples are prefix free.
106
+
97
107
  ## Render
98
108
 
99
109
  When you have a template named `header` with the given content:
@@ -16,6 +16,9 @@ module StylusAssets
16
16
 
17
17
  # The JavaScript Style template namespace
18
18
  attr_accessor :namespace
19
+
20
+ # The variable prefix
21
+ attr_accessor :variable_prefix
19
22
  end
20
23
 
21
24
  # By default the namespace is JSST (JavaScript Style template)
@@ -27,6 +30,9 @@ module StylusAssets
27
30
  # The default mime type of the tilt template
28
31
  self.default_mime_type = 'application/javascript'
29
32
 
33
+ # If the variable should be prefixed with a $ sign
34
+ self.variable_prefix = false
35
+
30
36
  # Test if the compiler is initialized.
31
37
  #
32
38
  # @return [Boolean] the initialization status
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module StylusAssets
4
- VERSION = '0.2.0' unless defined?(StylusAssets::VERSION)
4
+ VERSION = '0.3.0' unless defined?(StylusAssets::VERSION)
5
5
  end
@@ -2,6 +2,12 @@
2
2
  #
3
3
  class window.StylusAssets
4
4
 
5
+ # Whether to prefix variables with a $ on not
6
+ @prefixVariables = <%= StylusAssets::StylusTemplate.variable_prefix %>
7
+
8
+ # Test if object is an array
9
+ @isArray = Array.isArray or (obj) -> !!(obj and obj.concat and obj.unshift and not obj.callee)
10
+
5
11
  # Render stylus css with its variables to plain css
6
12
  #
7
13
  # @param [String] css the stylus css
@@ -12,21 +18,27 @@ class window.StylusAssets
12
18
  @render: (name, css, variables = {}, doc = undefined) ->
13
19
  result = undefined
14
20
  newVariables = {}
15
-
21
+ prefix = if StylusAssets.prefixVariables then '$' else ''
22
+
16
23
  # Replace existing less variables
17
24
  #
18
25
  for variable, value of variables
19
- existing = ///#{ variable }\s*=\s*[^;\n]+;?///
26
+ existing = ///\$?#{ variable }\s*=.*///
27
+
28
+ if StylusAssets.isArray(value)
29
+ list = ''
30
+ list += "'#{ v }' " for v in value
31
+ value = list.substring(0, list.length - 1)
20
32
 
21
33
  if existing.test css
22
- css = css.replace existing, "#{ variable } = #{ value }"
34
+ css = css.replace existing, "#{ prefix }#{ variable } = #{ value }"
23
35
  else
24
36
  newVariables[variable] = value
25
37
 
26
38
  # Add bew Stylus variables
27
39
  #
28
40
  style = ''
29
- style += "#{ variable } = #{ value }\n" for variable, value of newVariables
41
+ style += "#{ prefix }#{ variable } = #{ value }\n" for variable, value of newVariables
30
42
  style += css
31
43
 
32
44
  # Compile the Stylus stylesheet
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stylus_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-21 00:00:00.000000000 Z
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -71,7 +71,7 @@ files:
71
71
  - lib/stylus_assets/version.rb
72
72
  - lib/stylus_assets.rb
73
73
  - vendor/assets/javascripts/stylus.js
74
- - vendor/assets/javascripts/stylus_assets.js.coffee
74
+ - vendor/assets/javascripts/stylus_assets.js.coffee.erb
75
75
  - LICENSE
76
76
  - README.md
77
77
  homepage: https://github.com/netzpirat/stylus_assets
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: 1828645846812234919
91
+ hash: -1206232681905005782
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  none: false
94
94
  requirements: