nov-stylus 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab0aa9dc4ad044156ba701e1487792aee03a6f0e
4
+ data.tar.gz: a141a351f852c512760235d1449e25f17945d233
5
+ SHA512:
6
+ metadata.gz: e80674050e314d3d58a6fc33d19bfd095d8ad845624a1db3b13c628dcb263882921fb3502ca8aed314b5b0cf64052c5bfc8640e7e7651238866f2251a93d70f3
7
+ data.tar.gz: 02a31e6e5314b220c7b607749df6c552aa15fa9b0ebb592c6234d71208d6702ab2376ae0839bc676f5cc2de2755b24799c95fa59ab5ac7c1323b7f51b146ba78
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ### 1.0.1
2
+
3
+ * Prevent exceptions from files without extensions.
4
+
5
+ ### 1.0.0
6
+
7
+ * Rails 4+ and Ruby 1.9.x/2.0.0 support.
8
+ * Support for the `asset-path` and `asset-url` mixins, thanks to [@spilin](https://github.com/spilin).
9
+
10
+ Please check [0-7-stable](https://github.com/lucasmazza/ruby-stylus/blob/0-7-stable/CHANGELOG.md) for previous changes.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2012-2015 Lucas Mazza; 2015 Forge Software, LLC.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # Ruby Stylus
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/stylus.svg)](http://badge.fury.io/rb/stylus)
4
+ [![Build Status](https://travis-ci.org/forgecrafted/ruby-stylus.svg?branch=master)](https://travis-ci.org/forgecrafted/ruby-stylus)
5
+ [![Coverage Status](https://coveralls.io/repos/forgecrafted/ruby-stylus/badge.svg)](https://coveralls.io/r/forgecrafted/ruby-stylus)
6
+
7
+ `stylus` is a bridge between Ruby and the [Stylus](https://github.com/stylus/stylus) library that runs on [node.js](http://nodejs.org). It has support for Rails 4 applications. (if you are working with Rails 3, check the [0-7-stable](https://github.com/forgecrafted/ruby-stylus/tree/0-7-stable) branch.)
8
+
9
+ ## Installation
10
+
11
+ If you have a `Gemfile`:
12
+
13
+ ```
14
+ gem 'stylus'
15
+ ```
16
+
17
+ or install it on your system:
18
+
19
+ ```
20
+ gem install stylus
21
+ ```
22
+
23
+ The [ruby-stylus-source](https://github.com/forgecrafted/ruby-stylus-source) packages the Stylus source into a gem, and is installed as a dependency of this gem. Versions of `ruby-stylus-source` follow Stylus releases and their versions.
24
+
25
+ You can manually replace the Stylus code by placing another version of Stylus on `./node_modules/stylus`, and it will be used instead of the version bundled inside the gem.
26
+
27
+ **REMEMBER**, you still need the `node` command available on your runtime for this gem to work. This gem is also compatible with the Heroku Cedar stack, enabling asset compilation during the deployment of your apps. You can check the [Node.js wiki](https://github.com/joyent/node/wiki/Quick-and-easy-installation) for more info.
28
+
29
+ ## Usage
30
+
31
+ The interaction is done by the `Stylus` module. You can compile Stylus syntax to CSS, convert it back, enable plugins and tweak some other options:
32
+
33
+ ```ruby
34
+ require 'stylus'
35
+
36
+ # Accepts a raw string or an IO object (File, StringIO or anything that responds to 'read').
37
+ Stylus.compile(File.new('application.styl')) # returns the compiled stylesheet.
38
+
39
+ # Use the :compress option, removing most newlines from the code.
40
+ Stylus.compile(File.read('application.styl'), compress: true)
41
+
42
+ # Or use the global compress flag
43
+ Stylus.compress = true
44
+ Stylus.compile(File.read('application.styl'))
45
+
46
+ # Convert old and boring CSS to awesome Stylus.
47
+ Stylus.convert(File.new('file.css'))
48
+
49
+ # Import plugins directly from Node.js, like nib.
50
+ Stylus.use :nib
51
+
52
+ # Enable debug info, which sends the 'linenos' and 'firebug' options to Stylus.
53
+ # If you provide a raw content String to the `Stylus.compile` method, remember to send
54
+ # a `:filename` option so Stylus can locate your stylesheet for proper inspection.
55
+ Stylus.debug = true
56
+ ```
57
+
58
+ ### With Rails and the Asset Pipeline.
59
+
60
+ Adding `stylus` to your Gemfile should let you work with `.styl` files with the Rails 3.1 Pipeline. Any asset generated with `rails generate` will be created with a `.css.styl` extension.
61
+
62
+ Any `@import` directive will add the stylesheet as a sprockets dependency, so you can update external libraries and it will reflect on your assets fingerprints. Also, the Sprockets load path (usually `app/assets`, `lib/assets`, `vendor/assets` and the `assets` folder inside any other gem) will be available to your stylesheets.
63
+
64
+ If the `config.assets.debug` is turned on, Stylus will emit extra comments on your stylesheets to help debugging and inspection using the `linenos` and `firebug` options. Check the [FireStylus extension for Firebug](https://github.com/stylus/stylus/blob/master/docs/firebug.md) for more info.
65
+
66
+ It should be noted that in a default rails project you should also remove the sass-rails gem. This gem includes the tilt gem required by the asset pipeline so you should also add that gem back on its own.
67
+
68
+ ```
69
+ # gem 'sass-rails'
70
+ gem 'tilt'
71
+ ```
72
+
73
+ For compilation of assets during deployment (e.g. for heroku) you'll also need to enable/add the rubyracer gem.
74
+
75
+ ```
76
+ # See https://github.com/rails/execjs#readme for more supported runtimes
77
+ gem 'therubyracer', platforms: :ruby
78
+ ```
79
+
80
+ ### `@import` and file extensions.
81
+
82
+ Stylus and Sprockets file lookups differ on the subject of handling file extensions, and that may hurt a bit.
83
+
84
+ If you use Stylus `@import` to expose variables, mixins or just to concatenate code, you should use only the `.styl` extension on your imported files. If you use the `.css.styl` form (a convention from Sprockets), Stylus will treat it as a plain CSS file since it has `.css` on its name.
85
+
86
+ ```sass
87
+ // imports mixins.styl
88
+ @import 'mixins'
89
+ ```
90
+
91
+ ### `@import` dependency resolution
92
+
93
+ Because of how sprockets handles dependency resolution for computing file changes and expiring caches, it is necessary to specify the full import path in your import statements.
94
+
95
+ That is, given:
96
+
97
+ ```
98
+ app/assets/stylesheets/
99
+ app/assets/stylesheets/file.styl
100
+ app/assets/stylesheets/some_directory/other_file.styl
101
+ app/assets/stylesheets/some_directory/another_file.styl
102
+ ```
103
+
104
+ Imports should be specified with the full path relative to `app/assets/stylesheets` regardless of where the file calling the import is. In this example we use the `app/assets` directory, but this also applies to `vendor/assets` and `lib/assets`.
105
+
106
+ ```ruby
107
+ # app/assets/stylesheets/file.styl
108
+ @import "some_directory/other_file.styl"
109
+
110
+ # app/assets/stylesheets/some_directory/other_file.styl
111
+ @import "some_directory/another_file.styl"
112
+ ```
113
+
114
+ This will ensure that all changes get reflected when any of the imported
115
+ files change. If you don't do this, sprockets will not accurately be
116
+ able to keep track of your dependencies.
117
+
118
+ ### Standalone Sprockets usage
119
+
120
+ If you're using Sprockets outside Rails, on Sinatra or on a plain Rack app, you can wire up Stylus inside a instance of `Sprockets::Environment` with the `Stylus.setup` method.
121
+
122
+ An example of serving stylesheets from `./stylesheets` using just Sprockets and Rack.
123
+
124
+ ```ruby
125
+ require 'sprockets'
126
+ require 'stylus/sprockets'
127
+
128
+ # Serve your stylesheets living on ./stylesheets
129
+ assets = Sprockets::Environment.new
130
+ assets.append_path('stylesheets')
131
+
132
+ Stylus.setup(assets)
133
+
134
+ # Run the Sprockets with Rack
135
+ map('/assets') { run assets.index }
136
+ ```
137
+
138
+ ## Plugins
139
+
140
+ [Stylus](https://github.com/stylus/stylus) exposes a nice API to create plugins written on [node.js](http://nodejs.org), like [nib](https://github.com/visionmedia/nib). The installation process should be the same as described above for [Stylus](https://github.com/stylus/stylus) (since they're all npm packages after all). You can hook them up on your Ruby code with `Stylus.use`:
141
+
142
+ ```ruby
143
+ Stylus.use :fingerprint, literal: 'caa8c262e23268d2a7062c6217202343b84f472b'
144
+ ```
145
+
146
+ Will run something like this in JavaScript:
147
+
148
+ ```javascript
149
+ stylus(file).use(fingerprint({literal:'caa8c262e23268d2a7062c6217202343b84f472b'}));
150
+ ```
151
+
152
+ ## Questions, Bugs or Support
153
+
154
+ [Drop us a line in the issues section](https://github.com/forgecrafted/ruby-stylus/issues).
155
+
156
+ **Be sure to include sample code that reproduces the problem.**
157
+
158
+ For more info about Stylus syntax and its features, you can check the [project repository](https://github.com/stylus/stylus), and the docs on the [GitHub page](http://stylus.github.io/stylus/).
159
+
160
+ ## Changelog
161
+
162
+ [Available here.](https://github.com/forgecrafted/ruby-stylus/blob/master/CHANGELOG.md)
163
+
164
+ ## License
165
+
166
+ Copyright (c) 2012-2015 Lucas Mazza; 2015 Forge Software, LLC.
167
+
168
+ This is free software, and may be redistributed under the terms specified in the LICENSE file.
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module Stylus
4
+ module Generators
5
+ class AssetsGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_stylus
9
+ template 'stylesheet.css.styl', File.join('app/assets/stylesheets', class_path, "#{file_name}.css.styl")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the matching controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Stylus syntax here: http://learnboost.github.io/stylus
@@ -0,0 +1,11 @@
1
+ require 'rails/generators/css/scaffold/scaffold_generator'
2
+
3
+ module Stylus
4
+ module Generators
5
+ # Just inherit from the original Generator from Rails
6
+ # because `scaffold.css` it's just to help people to start up
7
+ # their Rails applications.
8
+ class ScaffoldGenerator < Css::Generators::ScaffoldGenerator
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,71 @@
1
+ # Based on the ImportProcessor from the less-rails gem, by @metaskills
2
+ module Stylus
3
+ # Internal: A Tilt template that tracks down '@import' declarations
4
+ # and marks them as a dependency on the current asset.
5
+ #
6
+ # Example
7
+ #
8
+ # @import 'dashboard'
9
+ # # => A '//= depend_on dashboard' directive can be ommited from the stylesheet.
10
+ class ImportProcessor < Tilt::Template
11
+
12
+ IMPORT_SCANNER = /@import\s*['"]([^'"]+)['"]\s*/.freeze
13
+
14
+ # Internal: Tilt default interface requirement.
15
+ #
16
+ # Returns nothing.
17
+ def prepare
18
+ end
19
+
20
+ # Public: Scans the current stylesheet to track down Stylus
21
+ # '@import' calls as dependencies.
22
+ #
23
+ # Returns the stylesheet content, unmodified.
24
+ def evaluate(context, locals, &block)
25
+ return data unless stylus_file?(context)
26
+
27
+ depend_on(context, data)
28
+ data
29
+ end
30
+
31
+ private
32
+
33
+ # Internal: Returns true if the file being processed counts as a
34
+ # Stylus file (That is, it has a .styl extension).
35
+ def stylus_file?(context)
36
+ File.fnmatch('*.styl', file) || File.fnmatch('*.styl.*', file)
37
+ end
38
+
39
+ # Internal: Scan the stylesheet body, looking for '@import' calls to
40
+ # declare them as a dependency on the context using 'depend_on' method.
41
+ # This method will recursively scans all dependency to ensure that
42
+ # the current stylesheet tracks down nested dependencies.
43
+ def depend_on(context, data)
44
+ dependencies = data.scan(IMPORT_SCANNER).flatten.compact.uniq
45
+
46
+ dependencies.each do |path|
47
+ asset = resolve(context, path)
48
+
49
+ if asset
50
+ context.depend_on(asset)
51
+ depend_on(context, File.read(asset))
52
+ end
53
+ end
54
+ end
55
+
56
+ # Internal: Resolves the given 'path' with the Sprockets context, but
57
+ # avoids 'Sprockets::FileNotFound' exceptions since we might be importing
58
+ # files outside the Sprockets load path - like "nib".
59
+ #
60
+ # Returns the resolved 'Asset' or nil if it can't be found.
61
+ def resolve(context, path)
62
+ context.resolve(path, content_type: 'text/css')
63
+ rescue ::Sprockets::FileNotFound
64
+ begin
65
+ context.resolve(path + '/index', content_type: 'text/css')
66
+ rescue
67
+ nil
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,32 @@
1
+ require 'stylus'
2
+ require 'stylus/sprockets'
3
+
4
+ module Stylus
5
+ # Internal: The Railtie responsible for integrate the Stylus library with
6
+ # a Rails application.
7
+ #
8
+ # Some of the customizations of using Stylus alongside Rails:
9
+ #
10
+ # * The application will use the Stylus stylesheet engine;
11
+ # * The Sprockets instance (present at Rails.application.assets) will be configured
12
+ # with the Stylus templates and the configurations defined at 'config.assets' will
13
+ # affect how Stylus compile your stylesheets;
14
+ # * The assets load path - the folders living on app/assets/stylesheets,
15
+ # lib/assets/stylesheets and vendor/assets/stylesheets on your app - will be
16
+ # added to the Stylus path registry.
17
+ class Railtie < ::Rails::Railtie
18
+
19
+ # Internal: Set the Stylesheet engine to 'stylus', so the generator constants
20
+ # will be loaded from the `Stylus::Generators` namespace.
21
+ config.app_generators.stylesheet_engine :stylus
22
+
23
+ # Internal: Initializer block that uses the Stylus.setup utility to configure
24
+ # both Stylus and the Sprockets instance that lives on 'app.assets'. The entire
25
+ # configuration object will be passed along.
26
+ #
27
+ # Returns nothing.
28
+ config.assets.configure do |env|
29
+ Stylus.setup(env, config.assets.merge(rails: true))
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ var stylus = require('stylus');
2
+
3
+ function compile(str, options, plugins, imports, definitions) {
4
+ var style = stylus(str, options);
5
+ var output = '';
6
+
7
+ for(var name in plugins) {
8
+ var fn = require(name);
9
+ style.use(fn(plugins[name]));
10
+ }
11
+
12
+ imports.forEach(function(path) {
13
+ style.import(path);
14
+ })
15
+
16
+ for(var definition in definitions) {
17
+ obj = definitions[definition];
18
+ value = obj.value
19
+
20
+ if(obj.literal) {
21
+ value = new stylus.nodes.Literal(value);
22
+ }
23
+
24
+ style.define(definition, value);
25
+ }
26
+
27
+ style.render(function(error, css) {
28
+ if(error) throw error;
29
+ output = css;
30
+ })
31
+ return output;
32
+ }
33
+
34
+ function convert(str) {
35
+ return stylus.convertCSS(str);
36
+ }
37
+
38
+ function version() {
39
+ return stylus.version;
40
+ }
@@ -0,0 +1,20 @@
1
+ (function(program, execJS) { execJS(program) })(function() { #{source}
2
+ }, function(program) {
3
+ var output, print = function(string) {
4
+ process.stdout.write('' + string);
5
+ };
6
+ try {
7
+ result = program();
8
+ if (typeof result == 'undefined' && result !== null) {
9
+ print('["ok"]');
10
+ } else {
11
+ try {
12
+ print(JSON.stringify(['ok', result]));
13
+ } catch (err) {
14
+ print('["err"]');
15
+ }
16
+ }
17
+ } catch (err) {
18
+ print(JSON.stringify(['err', '' + err]));
19
+ }
20
+ });
@@ -0,0 +1,54 @@
1
+ require 'execjs'
2
+
3
+ module Stylus
4
+ # Internal: Module responsible for the ExecJS interaction. Besides handling
5
+ # the compilation execution, this module provide a runtime validation to ensure
6
+ # that the Node.JS binary is available to use.
7
+ module Runtime
8
+ # Internal: Calls a specific function on the Node.JS context.
9
+ #
10
+ # Example
11
+ # exec('version', 2) # => '2'
12
+ #
13
+ # Returns The function returned value.
14
+ def exec(*arguments)
15
+ check_availability!
16
+ context.call(*arguments)
17
+ end
18
+
19
+ private
20
+ # Internal: Queries the runtime for it's availability and raises a 'RuntimeError'
21
+ # if the runtime isn't available. Otherwise, this is a noop.
22
+ def check_availability!
23
+ unless runtime.available?
24
+ message = 'The Node.JS runtime is not available to Stylus.'
25
+ message << 'Ensure that the "node" (or "nodejs") executable is present in your $PATH.'
26
+ raise RuntimeError, message
27
+ end
28
+ end
29
+
30
+ # Internal: Compile the Stylus compilation script into a execution context
31
+ # to execute functions into.
32
+ #
33
+ # Returns the compiled context.
34
+ def context
35
+ @context ||= runtime.compile(script)
36
+ end
37
+
38
+ # Internal: The custom compilation script body.
39
+ def script
40
+ File.read(File.expand_path('../runtime/compiler.js',__FILE__))
41
+ end
42
+
43
+ # Internal: Create the ExecJS external runtime with a old runner script that
44
+ # maintains the state of 'require', so we can use it to load modules like on
45
+ # any Node.JS program.
46
+ def runtime
47
+ @runtime ||= ExecJS::ExternalRuntime.new(
48
+ name: 'Node.js (V8)',
49
+ command: ['nodejs', 'node'],
50
+ runner_path: File.expand_path('../runtime/runner.js', __FILE__)
51
+ )
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,59 @@
1
+ require 'stylus'
2
+ require 'stylus/tilt/stylus'
3
+ require 'stylus/tilt/rails'
4
+ require 'stylus/import_processor'
5
+ # Public: The setup logic to configure both Stylus and Sprockets on any
6
+ # kind of application - Rails, Sinatra or Rack.
7
+ #
8
+ # Example
9
+ #
10
+ # # mounting Sprockets as a Rack application with Stylus
11
+ # assets = Sprockets::Environment.new
12
+ # assets.append_path 'stylesheets'
13
+ # Stylus.setup(assets)
14
+ # run assets.index
15
+ module Stylus
16
+ # Public: Configure a Sprockets environment with Stylus Tilt engine
17
+ # and the ImportProcessor. It also accept a configuration Hash to
18
+ # setup the load path and flags of the Stylus module.
19
+ #
20
+ # environment - A instance of Sprockets::Environment.
21
+ # options - The configuration Hash (default: {})
22
+ # :rails - a flag to inform that the current application is a Rails app.
23
+ # :paths - An Array of paths to use the '@import' directive, defaults
24
+ # to the `paths` attribute on the environment object.
25
+ # :debug - The Boolean value for the debug flag.
26
+ # :compress - The Boolean value for the debug compress.
27
+ #
28
+ # Example
29
+ #
30
+ # assets = Sprockets::Environment.new
31
+ # Stylus.setup(assets, compress: settings.production?)
32
+ #
33
+ # Returns nothing.
34
+ def self.setup(environment, options = {})
35
+ paths = options[:paths] || environment.paths
36
+
37
+ Stylus.paths.concat(paths)
38
+
39
+ Stylus.debug = options.fetch(:debug, Stylus.debug)
40
+ Stylus.compress = options.fetch(:compress, Stylus.compress)
41
+ template = detect_template_hander(options)
42
+ environment.register_mime_type 'text/styl', extensions: ['.styl']
43
+ environment.register_mime_type 'text/css', extensions: ['.css']
44
+ environment.register_transformer 'text/styl', 'text/css', template
45
+ end
46
+
47
+ # Internal: Gets the desired Tilt template handler to the current configuration.
48
+ # If a 'rails' option is present then the Rails specific template will be
49
+ # returned instead of the default Stylus Tilt template.
50
+ #
51
+ # Returns a Tilt::Template children class.
52
+ def self.detect_template_hander(options = {})
53
+ if options[:rails]
54
+ Stylus::Rails::StylusTemplate
55
+ else
56
+ Tilt::StylusTemplate
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,53 @@
1
+ require 'stylus/tilt/stylus'
2
+ # Public: A Tilt template to compile Stylus stylesheets with asset helpers.
3
+ module Stylus
4
+ module Rails
5
+ class StylusTemplate < ::Tilt::StylusTemplate
6
+ EXCLUDED_EXTENSIONS = %w{ css js gzip json md html }
7
+
8
+ # Public: The default mime type for stylesheets.
9
+ self.default_mime_type = 'text/css'
10
+
11
+ # Internal: Appends stylus mixin for asset_url and asset_path support
12
+ def evaluate(scope, locals, &block)
13
+ @data = build_mixin_body(scope) + data
14
+ super
15
+ end
16
+
17
+ protected
18
+
19
+ # Internal: Builds body of a mixin
20
+ #
21
+ # Returns string representation of a mixin with asset helper functions
22
+ def build_mixin_body(scope)
23
+ @mixin_body ||= if assets_hash(scope).values.all? {|value| value != '' }
24
+ <<-STYL
25
+ asset-url(key)
26
+ return pair[1] if pair[0] == key for pair in #{assets_hash(scope)[:url]} ()
27
+ asset-path(key)
28
+ return pair[1] if pair[0] == key for pair in #{assets_hash(scope)[:path]} ()
29
+ STYL
30
+ else
31
+ ''
32
+ end
33
+ end
34
+
35
+ # Internal: Construct Hash with absolute/relative paths in stylus syntax.
36
+ #
37
+ # Returns string representations of hash in Stylus syntax
38
+ def assets_hash(scope)
39
+ @assets_hash ||= scope.environment.each_logical_path.each_with_object({ :url => '', :path => '' }) do |logical_path, assets_hash|
40
+ extensions = EXCLUDED_EXTENSIONS.join('|')
41
+ unless File.extname(logical_path) =~ Regexp.new("^(\.(#{extensions})|)$")
42
+ path_to_asset = scope.path_to_asset(logical_path)
43
+ assets_hash[:url] << "('#{logical_path}' url(\"#{path_to_asset}\")) "
44
+ assets_hash[:path] << "('#{logical_path}' \"#{path_to_asset}\") "
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+
53
+ Tilt.register ::Stylus::Rails::StylusTemplate, 'styl'
@@ -0,0 +1,52 @@
1
+ require 'tilt'
2
+ # Public: A Tilt template to compile Stylus stylesheets.
3
+ #
4
+ # Examples
5
+ #
6
+ # template = Tilt::StylusTemplate.new { |t| File.read('app.styl') }
7
+ # template.render # => the compiled CSS from the app.styl file.
8
+ #
9
+ # Options should assigned on the template constructor.
10
+ # template = Tilt::StylusTemplate.new(compress: true) { |t| File.read('app.styl') }
11
+ # template.render # => the compiled CSS with compression enabled.
12
+ module Tilt
13
+ class StylusTemplate < Template
14
+
15
+ # Public: The default mime type for stylesheets.
16
+ self.default_mime_type = 'text/css'
17
+
18
+ # Internal: Checks if the Stylus module has been properly defined.
19
+ #
20
+ # Returns true if the 'Stylus' module is present.
21
+ def self.engine_initialized?
22
+ defined? ::Stylus
23
+ end
24
+
25
+ # Internal: Require the 'stylus' file to load the Stylus module.
26
+ #
27
+ # Returns nothing.
28
+ def initialize_engine
29
+ require_template_library 'stylus'
30
+ end
31
+
32
+ # Internal: Caches the filename as an option entry if it's present.
33
+ #
34
+ # Returns nothing.
35
+ def prepare
36
+ if self.file
37
+ options[:filename] ||= self.file
38
+ end
39
+ end
40
+
41
+ # Internal: Compile the template Stylus using this instance options.
42
+ # The current 'scope' and given 'locals' are ignored and the output
43
+ # is cached.
44
+ #
45
+ # Returns a String with the compiled stylesheet with CSS syntax.
46
+ def evaluate(scope, locals, &block)
47
+ @output ||= Stylus.compile(data, options)
48
+ end
49
+ end
50
+ end
51
+
52
+ Tilt.register Tilt::StylusTemplate, 'styl'
@@ -0,0 +1,2 @@
1
+ # require compatibility with older versions.
2
+ require 'stylus/tilt/stylus'
@@ -0,0 +1,3 @@
1
+ module Stylus
2
+ VERSION = '1.0.2'
3
+ end