slim-grunt-helpers 0.2.1 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1cdf8247c56df9ebc0368e2c5b09da63be94413
4
- data.tar.gz: a54e0cfe65a655fd4be2e62667655ca06f90de53
3
+ metadata.gz: cf34da52d8f48aa30ae95c45f5172aa29bd028d7
4
+ data.tar.gz: acfdb0dff87197e58d0234f8cbd2e6a6001b3ccf
5
5
  SHA512:
6
- metadata.gz: cd93bf79733566e214866f93ec64e2e3850128c29d623771b9e7b37c9aa41584205fb99d99f1694f413a2558375d4062df9a907e9e5cfdfbc9ce9207a4a92154
7
- data.tar.gz: 18f897ea8e7a70b5474289649c85d054e82ce917c6c604aa97de9df1cf0dd700bf5d0aa417869cc3df6e26f5ac5097c933fedd5dbf7433d686731ee6cd5bd570
6
+ metadata.gz: aba6abd560165176f53759c215a534ff8799578ea8a711ff15511ab2afc2ccc41e035940ea147aadbfc183173dfdf437bd54a360c6cd029db48e946cbf76b58d
7
+ data.tar.gz: cd6c112e2ef52d5e21458a3d9d1f3066ef2dc74a86749e782967c80a86f17091cab00ad995b8bc7f016df86ae6d884a7d7b627bc5199cc5a3ee31095acc91bd2
data/README.md CHANGED
@@ -68,6 +68,7 @@ The first argument is required, and it's the `path` :
68
68
  ```
69
69
 
70
70
  The `:alt` argument is optional and it's the `alternate search path`.
71
+ The `:absolute` argument is optional and if true, it will append '/' in tags to file paths when printing html.
71
72
  An object `usemin` will be yielded to the block which has only one method: **<<**.
72
73
  This method requires first argument which is path to your css file (http path) and the second argument is a
73
74
  hash of options which are appended as attributes to the link tag. Notice that on `link` tag,
@@ -80,7 +81,6 @@ Additionally, notice that attributes with `nil` or `false` as value are not set
80
81
 
81
82
  - `root_path` which is the path will be used as base directory (and **omitted in tags**)
82
83
  - `pattern` which is the pattern accepted by [Dir glob](http://ruby-doc.org/core-1.9.3/Dir.html#method-c-glob), used to search files
83
- - `relative` which if it's true, ensures file path won't start with `/` when printed in html
84
84
  - `options` which are directly passed to `require`
85
85
 
86
86
  ## Contributing
@@ -12,16 +12,17 @@ module SlimGruntHelpers
12
12
 
13
13
  # Options:
14
14
  # - `alt` which allows to set alternate paths which usemin should look into
15
+ # - `absolute` which ensures all files are prepended with '/' when true
15
16
  def sg_usemin_css(path, options={})
16
17
  usemin = SlimGruntHelpers::Models::UseminCss.new
17
- options = { alt: nil }.merge!(options)
18
+ options = { alt: nil, absolute: false }.merge!(options)
18
19
 
19
20
  alt = ''
20
21
  alt = "(#{ options[:alt] })" unless options[:alt].nil?
21
22
 
22
23
  text = "\n<!-- build:css#{ alt } #{ path } -->\n"
23
24
  yield(usemin)
24
- usemin.each do |link|
25
+ usemin.each(options) do |link|
25
26
  text << "#{ link }\n"
26
27
  end
27
28
  text << "<!-- endbuild -->\n"
@@ -29,16 +30,17 @@ module SlimGruntHelpers
29
30
 
30
31
  # Options:
31
32
  # - `alt` which allows to set alternate paths which usemin should look into
33
+ # - `absolute` which ensures all files are prepended with '/' when true
32
34
  def sg_usemin_js(path, options={})
33
35
  usemin = SlimGruntHelpers::Models::UseminJs.new
34
- options = { alt: nil }.merge!(options)
36
+ options = { alt: nil, absolute: false }.merge!(options)
35
37
 
36
38
  alt = ''
37
39
  alt = "(#{ options[:alt] })" unless options[:alt].nil?
38
40
 
39
41
  text = "\n<!-- build:js#{ alt } #{ path } -->\n"
40
42
  yield(usemin)
41
- usemin.each do |link|
43
+ usemin.each(options) do |link|
42
44
  text << "#{ link }\n"
43
45
  end
44
46
  text << "<!-- endbuild -->\n"
@@ -22,15 +22,15 @@ module SlimGruntHelpers
22
22
  self.include(path, options) unless file_already_included? path
23
23
  end
24
24
 
25
- def each
26
- @links.each { |link| yield(transform_link(link)) }
25
+ def each(options={})
26
+ @links.each { |link| yield(transform_link(link, options)) }
27
27
  end
28
28
 
29
29
  def base_options
30
30
  BASE_OPTIONS
31
31
  end
32
32
 
33
- def require_tree(root_path, pattern, relative=false, options={})
33
+ def require_tree(root_path, pattern, options={})
34
34
  unless root_path.respond_to? :join
35
35
  root_path = Pathname.new(root_path.to_s)
36
36
  end
@@ -38,9 +38,8 @@ module SlimGruntHelpers
38
38
  Dir[root_path.join(pattern).to_s].reject do |file|
39
39
  File.directory? file
40
40
  end.each do |file|
41
- file_name = file.to_s
42
- real_root_path = root_path.to_s
43
- real_root_path += '/' if relative
41
+ file_name = file.to_s
42
+ real_root_path = "#{ root_path }/"
44
43
  file_name[real_root_path] = ''
45
44
 
46
45
  self.require file_name, options
@@ -49,7 +48,7 @@ module SlimGruntHelpers
49
48
 
50
49
  protected
51
50
 
52
- def transform_link(link)
51
+ def transform_link(link, options={})
53
52
  raise NotImplementedError, 'This method must be implemented in child classes'
54
53
  end
55
54
 
@@ -14,8 +14,12 @@ module SlimGruntHelpers
14
14
 
15
15
  protected
16
16
 
17
- def transform_link(link)
18
- text = %Q{<link href="#{ link[:path] }"}
17
+ def transform_link(link, options={})
18
+ link_path = ''
19
+ link_path += '/' if options[:absolute]
20
+ link_path += link[:path].to_s
21
+
22
+ text = %Q{<link href="#{ link_path }"}
19
23
  link[:options].each do |key, value|
20
24
  if value == true
21
25
  text << %Q{ #{ key }}
@@ -8,8 +8,12 @@ module SlimGruntHelpers
8
8
 
9
9
  protected
10
10
 
11
- def transform_link(link)
12
- text = %Q{<script src="#{ link[:path] }"}
11
+ def transform_link(link, options={})
12
+ link_path = ''
13
+ link_path += '/' if options[:absolute]
14
+ link_path += link[:path].to_s
15
+
16
+ text = %Q{<script src="#{ link_path }"}
13
17
  link[:options].each do |key, value|
14
18
  if value == true
15
19
  text << %Q{ #{ key }}
@@ -1,3 +1,3 @@
1
1
  module SlimGruntHelpers
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim-grunt-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fire-Dragon-DoL