slim-grunt-helpers 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/lib/slim-grunt-helpers.rb +7 -0
- data/lib/slim-grunt-helpers/helpers.rb +49 -0
- data/lib/slim-grunt-helpers/models.rb +3 -0
- data/lib/slim-grunt-helpers/models/usemin.rb +35 -0
- data/lib/slim-grunt-helpers/models/usemin_css.rb +31 -0
- data/lib/slim-grunt-helpers/models/usemin_js.rb +31 -0
- data/lib/slim-grunt-helpers/version.rb +3 -0
- data/slim_grunt_helpers.gemspec +23 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66aac7b8f9dd3c5fe219e1be98ad6b3663020782
|
4
|
+
data.tar.gz: 8925791b026acd526ff6252f3300f9d218bc2b4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1554c2ce726454148dcef5cb19ee9456cd4d5eddf669fd68c9e7ce9b9f55a8a1d002f58e71085d18c54e756b91fc31671e45dbbbdc47b5e10212d837fe44bc69
|
7
|
+
data.tar.gz: f1f583ebf185b6335c4f1729e5ee9a3c098e819bd3ace0450b8d61c3d0a1a27d3d2cc69611f76e3b9a84723272b752dacba066e66815bebb22b074c8bf3e5d57
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Fire-Dragon-DoL
|
2
|
+
|
3
|
+
MIT License
|
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
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# SlimGruntHelpers
|
2
|
+
|
3
|
+
This gem injects a set of helpers in Ruby global namespace (or not, depending on
|
4
|
+
how you require the gem) which will help you when setting up a pipeline with
|
5
|
+
[Grunt](http://gruntjs.com/) and [Slim](https://github.com/slim-template/slim) template language.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'slim-grunt-helpers', '~> 0.0.1'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install slim-grunt-helpers
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
The easiest way is to just use bundler and so `Bundle.require(:default)`, which will inject code in
|
26
|
+
global namespace (notice that in any case every method is prefixed with **sg_**).
|
27
|
+
Otherwise, if you don't want to pollute your global namespace you can change your Gemfile configuration into:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'slim-grunt-helpers', require: ['slim-grunt-helpers/helpers']
|
31
|
+
```
|
32
|
+
|
33
|
+
And you'll need to `include SlimGruntHelpers::Helpers` in some place to have methods available.
|
34
|
+
|
35
|
+
## Available helpers
|
36
|
+
|
37
|
+
Right now, only a few helpers are available, I'll add others in future.
|
38
|
+
|
39
|
+
#### sg\_enclose\_newline
|
40
|
+
|
41
|
+
Takes a `block` as an argument, just encloses the block in `\n#{ block }\n`
|
42
|
+
|
43
|
+
#### sg\_usemin\_css / sg\_usemin\_js
|
44
|
+
|
45
|
+
These two methods behave in the same way. The purpose is to use them with the very helpful
|
46
|
+
[grunt-usemin](https://github.com/yeoman/grunt-usemin) plugin which however requires some new lines here and
|
47
|
+
there which are boring to type directly in Slim. The usage is simple:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
== sg_usemin_css('application.css', alt: '.tmp') do |usemin|
|
51
|
+
- usemin << 'styles/bootstrap.css'
|
52
|
+
- usemin << 'styles/main.css', 'data-customattr' => 'customdata'
|
53
|
+
```
|
54
|
+
|
55
|
+
The first argument is required, and it's the `path` :
|
56
|
+
|
57
|
+
```html
|
58
|
+
<!-- build:<type>(alternate search path) <path> -->
|
59
|
+
```
|
60
|
+
|
61
|
+
The `:alt` argument is optional and it's the `alternate search path`.
|
62
|
+
An object `usemin` will be yielded to the block which has only one method: **<<**.
|
63
|
+
This method requires first argument which is path to your css file (http path) and the second argument is a
|
64
|
+
hash of options which are appended as attributes to the link tag. Notice that on `link` tag,
|
65
|
+
`rel="stylesheet"` is automatically appended (and can be overwritten by specifying a `rel` key in options).
|
66
|
+
Additionally, notice that attributes with `nil` or `false` as value are not set (so you can remove `rel`), while those with `true` are set but without value and without `=""`.
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Required so that if you include only the helpers file, version is still there
|
2
|
+
require 'slim-grunt-helpers/version'
|
3
|
+
require 'slim-grunt-helpers/models'
|
4
|
+
|
5
|
+
module SlimGruntHelpers
|
6
|
+
|
7
|
+
module Helpers
|
8
|
+
|
9
|
+
def sg_enclose_newline
|
10
|
+
%Q{\n#{ yield }\n}
|
11
|
+
end
|
12
|
+
|
13
|
+
# Options:
|
14
|
+
# - `alt` which allows to set alternate paths which usemin should look into
|
15
|
+
def sg_usemin_css(path, options={})
|
16
|
+
usemin = SlimGruntHelpers::Models::UseminCss.new
|
17
|
+
options = { alt: nil }.merge!(options)
|
18
|
+
|
19
|
+
alt = ''
|
20
|
+
alt = "(#{ options[:alt] })" unless options[:alt].nil?
|
21
|
+
|
22
|
+
text = "\n<!-- build:css#{ alt } #{ path } -->\n"
|
23
|
+
yield(usemin)
|
24
|
+
usemin.each do |link|
|
25
|
+
text << "#{ link }\n"
|
26
|
+
end
|
27
|
+
text << "\n<!-- endbuild -->"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Options:
|
31
|
+
# - `alt` which allows to set alternate paths which usemin should look into
|
32
|
+
def sg_usemin_js(path, options={})
|
33
|
+
usemin = SlimGruntHelpers::Models::UseminJs.new
|
34
|
+
options = { alt: nil }.merge!(options)
|
35
|
+
|
36
|
+
alt = ''
|
37
|
+
alt = "(#{ options[:alt] })" unless options[:alt].nil?
|
38
|
+
|
39
|
+
text = "\n<!-- build:js#{ alt } #{ path } -->\n"
|
40
|
+
yield(usemin)
|
41
|
+
usemin.each do |link|
|
42
|
+
text << "#{ link }\n"
|
43
|
+
end
|
44
|
+
text << "\n<!-- endbuild -->"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module SlimGruntHelpers
|
2
|
+
|
3
|
+
module Models
|
4
|
+
|
5
|
+
class Usemin
|
6
|
+
|
7
|
+
BASE_OPTIONS = {}.freeze
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@links = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def <<(path, options={})
|
14
|
+
@links << { path: path, options: base_options.merge(options) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def each
|
18
|
+
@links.each { |link| yield(transform_link(link)) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_options
|
22
|
+
BASE_OPTIONS
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def transform_link(link)
|
28
|
+
raise NotImplementedError, 'This method must be implemented in child classes'
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'slim-grunt-helpers/models/usemin'
|
2
|
+
|
3
|
+
module SlimGruntHelpers
|
4
|
+
|
5
|
+
module Models
|
6
|
+
|
7
|
+
class UseminCss < Usemin
|
8
|
+
|
9
|
+
BASE_OPTIONS = { rel: 'stylesheet' }.freeze
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def transform_link(link)
|
14
|
+
text = %Q{<link href="#{ link[:path] }"}
|
15
|
+
link[:options].each do |key, value|
|
16
|
+
if value == true
|
17
|
+
text << %Q{ #{ key }}
|
18
|
+
elsif value
|
19
|
+
text << %Q{ #{ key }="#{ value }"}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
text << ' />'
|
23
|
+
|
24
|
+
text
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'slim-grunt-helpers/models/usemin'
|
2
|
+
|
3
|
+
module SlimGruntHelpers
|
4
|
+
|
5
|
+
module Models
|
6
|
+
|
7
|
+
class UseminJs < Usemin
|
8
|
+
|
9
|
+
BASE_OPTIONS = {}.freeze
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def transform_link(link)
|
14
|
+
text = %Q{<script src="#{ link[:path] }"}
|
15
|
+
link[:options].each do |key, value|
|
16
|
+
if value == true
|
17
|
+
text << %Q{ #{ key }}
|
18
|
+
elsif value
|
19
|
+
text << %Q{ #{ key }="#{ value }"}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
text << '></script>'
|
23
|
+
|
24
|
+
text
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'slim-grunt-helpers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "slim-grunt-helpers"
|
8
|
+
spec.version = SlimGruntHelpers::VERSION
|
9
|
+
spec.authors = ["Fire-Dragon-DoL"]
|
10
|
+
spec.email = ["francesco.belladonna@gmail.com"]
|
11
|
+
spec.description = %q{Small set of helpers that can be used in slim templates}
|
12
|
+
spec.summary = %q{Small set of helpers that can be used in slim templates}
|
13
|
+
spec.homepage = "https://github.com/Fire-Dragon-DoL/slim-grunt-helpers"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slim-grunt-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fire-Dragon-DoL
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Small set of helpers that can be used in slim templates
|
42
|
+
email:
|
43
|
+
- francesco.belladonna@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/slim-grunt-helpers.rb
|
54
|
+
- lib/slim-grunt-helpers/helpers.rb
|
55
|
+
- lib/slim-grunt-helpers/models.rb
|
56
|
+
- lib/slim-grunt-helpers/models/usemin.rb
|
57
|
+
- lib/slim-grunt-helpers/models/usemin_css.rb
|
58
|
+
- lib/slim-grunt-helpers/models/usemin_js.rb
|
59
|
+
- lib/slim-grunt-helpers/version.rb
|
60
|
+
- slim_grunt_helpers.gemspec
|
61
|
+
homepage: https://github.com/Fire-Dragon-DoL/slim-grunt-helpers
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.1.11
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Small set of helpers that can be used in slim templates
|
85
|
+
test_files: []
|