linner 0.1.5 → 0.2.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: b1156772623483911f99bcb23fb8e7609a593748
4
- data.tar.gz: d0503752526db29a76957ca9bc7a18ea1506db6f
3
+ metadata.gz: 234c003d2a8de857346b8001b7d76f4e0e2dc1d3
4
+ data.tar.gz: 5f67d62fd866da6717fa56f619be7a8613a1c859
5
5
  SHA512:
6
- metadata.gz: c2cda5370061201ca4507e88d7f12c94cf22244229a5b7a69a6e72e47e25ac08dcdbd258650f4c82b1cf95b68656452064e572e1d2eb243b5623bfde4fa32694
7
- data.tar.gz: 33431b81c8bb1dc6b7dace4cce86cf4376decc6f3d0a0b14082f4bd3c655fca08115ab43b691e83aa4e8c47d4173e208e89df4810cc6ab25220657b6a31115d9
6
+ metadata.gz: a78076faccfb160445dbe5c3846ba796e787c36a46c0f699f72890e0837dee3ca62f237dd0d83c00772d0eb06fe5b648dd456021c70cdce85ba5c27519726d91
7
+ data.tar.gz: 2324de42bd8f6ab2fbb82a7a98b54e71fe61f20958edc4c2e798bebfe089dae86fd729c35c6813c873c607f5942703344ecfb7ef670fd19c1a59d4f271de91e8
data/lib/linner.rb CHANGED
@@ -25,48 +25,46 @@ module Linner
25
25
 
26
26
  def perform(compile: false)
27
27
  environment.files.each do |config|
28
- Thread.new {concat(config).each {|asset| asset.compress if compile; asset.write}}.join
29
- Thread.new {copy(config)}.join
28
+ concat(config, compile)
29
+ copy(config)
30
30
  end
31
31
  end
32
32
 
33
33
  private
34
- def concat(config)
35
- assets = []
36
- config["concat"].each do |dest, regex|
37
- Thread.new do
38
- dest = Asset.new(File.join environment.public_folder, dest)
39
- dest.content = ""
40
- Dir.glob(regex).uniq.sort_by_before_and_after(config["order"]["before"], config["order"]["after"]).each do |m|
41
- asset = Asset.new(m)
42
- content = asset.content
43
- if asset.wrappable?
44
- content = asset.wrap
45
- end
46
- dest.content << content
34
+ def concat(config, compile)
35
+ config["concat"].map do |dest, regex|
36
+ matches = Dir.glob(regex).uniq.order_by(before:config["order"]["before"], after:config["order"]["after"])
37
+ dest = Asset.new(File.join environment.public_folder, dest)
38
+ dest.content = ""
39
+ cached = matches.select do |path|
40
+ mtime = File.mtime(path).to_i
41
+ mtime == cache[path] ? false : cache[path] = mtime
42
+ end
43
+ next if cached.empty?
44
+ matches.each do |m|
45
+ asset = Asset.new(m)
46
+ content = asset.content
47
+ if asset.wrappable?
48
+ content = asset.wrap
47
49
  end
48
- assets << dest
49
- end.join
50
+ dest.content << content
51
+ end
52
+ dest.compress if compile
53
+ dest.write
50
54
  end
51
- assets
52
55
  end
53
56
 
54
57
  def copy(config)
55
58
  config["copy"].each do |dest, regex|
56
- Thread.new do
57
- Dir.glob(regex).each do |path|
58
- mtime = File.mtime(path).to_i
59
- if cache[path]
60
- next if mtime == cache[path]
61
- else
62
- cache[path] = mtime
63
- end
64
- logical_path = Asset.new(path).logical_path
65
- dest_path = File.join(environment.public_folder, dest, logical_path)
66
- FileUtils.mkdir_p File.dirname(dest_path)
67
- FileUtils.cp_r path, dest_path
68
- end
69
- end.join
59
+ Dir.glob(regex).each do |path|
60
+ mtime = File.mtime(path).to_i
61
+ next if cache[path] == mtime
62
+ cache[path] = mtime
63
+ logical_path = Asset.new(path).logical_path
64
+ dest_path = File.join(environment.public_folder, dest, logical_path)
65
+ FileUtils.mkdir_p File.dirname(dest_path)
66
+ FileUtils.cp_r path, dest_path
67
+ end
70
68
  end
71
69
  end
72
70
  end
@@ -15,10 +15,12 @@ module Linner
15
15
  end
16
16
  end
17
17
 
18
- %w(notification wrapper).each do |method|
19
- define_method(method) do
20
- @env[method]
21
- end
18
+ def notification
19
+ @env["notification"]
20
+ end
21
+
22
+ def wrapper
23
+ @env["modules"]["wrapper"]
22
24
  end
23
25
 
24
26
  def files
data/lib/linner/helper.rb CHANGED
@@ -7,15 +7,15 @@ module Linner
7
7
  end
8
8
  end
9
9
 
10
- module Sort
11
- def sort_by_before_and_after(before, after)
12
- sort_by_before(self, before)
13
- sort_by_after(self, after)
10
+ module Order
11
+ def order_by(before:[], after:[])
12
+ order_by_before(self, before)
13
+ order_by_after(self, after)
14
14
  self
15
15
  end
16
16
 
17
17
  private
18
- def sort_by_before(list, before)
18
+ def order_by_before(list, before)
19
19
  before.reverse.each do |f|
20
20
  if i = list.index {|x| x =~ /#{f}/i}
21
21
  list.unshift list.delete_at i
@@ -23,7 +23,7 @@ module Linner
23
23
  end
24
24
  end
25
25
 
26
- def sort_by_after(list, after)
26
+ def order_by_after(list, after)
27
27
  after.reverse.each do |f|
28
28
  if i = list.index {|x| x =~ /#{f}/i}
29
29
  list.push list.delete_at i
@@ -38,5 +38,5 @@ class Hash
38
38
  end
39
39
 
40
40
  class Array
41
- include Linner::Sort
41
+ include Linner::Order
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module Linner
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -7,21 +7,21 @@ describe Array do
7
7
 
8
8
  describe :sort do
9
9
  it "won't change when before and after are empty array" do
10
- @array.sort_by_before_and_after([], []).should be_equal @array
10
+ @array.order_by(before:[], after:[]).should be_equal @array
11
11
  end
12
12
 
13
13
  it "will change by before items" do
14
- @array.sort_by_before_and_after(["jquery.js", "vendor.js"], [])
14
+ @array.order_by(before:["jquery.js", "vendor.js"], after:[])
15
15
  @array.should =~ %w[jquery.js vendor.js app.js bootstrap.css reset.css]
16
16
  end
17
17
 
18
18
  it "will change by after items" do
19
- @array.sort_by_before_and_after([], ["reset.css", "bootstrap.css"])
19
+ @array.order_by(before:[], after:["reset.css", "bootstrap.css"])
20
20
  @array.should =~ %w[app.js jquery.js vendor.js reset.css bootstrap.css]
21
21
  end
22
22
 
23
23
  it "will change by before and after items" do
24
- @array.sort_by_before_and_after(["jquery.js", "vendor.js"], ["reset.css", "bootstrap.css"])
24
+ @array.order_by(before:["jquery.js", "vendor.js"], after:["reset.css", "bootstrap.css"])
25
25
  @array.should =~ %w[jquery.js vendor.js app.js reset.css bootstrap.css]
26
26
  end
27
27
  end
@@ -29,5 +29,6 @@ files:
29
29
  order:
30
30
  before: []
31
31
  after: []
32
- wrapper: "CMD"
32
+ modules:
33
+ wrapper: "CMD"
33
34
  notification: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-26 00:00:00.000000000 Z
11
+ date: 2013-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor