asset_packer 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fed08b143d17f83d7b3be23dcaba82a34f975260
4
- data.tar.gz: f4c6bb6e541dea3ad290fc7c6a8c819a4b0c98cf
3
+ metadata.gz: 3e37f7b09870b8072534b03416ba0a8c7d69f67f
4
+ data.tar.gz: 446434d07ecd47d498a73f6bb025b6e362aeb306
5
5
  SHA512:
6
- metadata.gz: e899b50645ee4bbffde1755cb68871f9819d2110f85848bdc737cba5bf48b7939d0f9c9d2871451ca507902b027342e1e26b686e4868b872c2faab3257c81b6b
7
- data.tar.gz: b607f34ef91361c3fa574a013c05f45c201c1168daf0185c07d73bbea573a2793dc87fd0ee6e659db128d36bf6dfccce5e0b981a4357340981c5aaefa1cdc6bd
6
+ metadata.gz: f4bfe009771b200a0762285f6ec7dfdb43be35f6807d4d25e98dc4a3d37a3215bfe9414dd99f86671cb0f6e3e91c5d931cfad6ef8946689362bc47210d7f6887
7
+ data.tar.gz: bf3a6e5946c338387aa50c735a460b0202e7c0ef1811be37801a4f4522893961b6487cd329757553e33318fed69ad6eee79ae8905ef84fe56296636800c2cdc5
data/.travis.yml CHANGED
@@ -2,12 +2,12 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.0
5
+ - 2.1.1
6
6
  - rbx
7
7
  - ruby-head
8
8
  matrix:
9
9
  allow_failures:
10
10
  - rvm: ruby-head
11
- - rvm: 2.1.0
11
+ - rvm: 2.1.1
12
12
  - rvm: rbx
13
13
  script: bundle exec rake mutant
data/Changelog.md CHANGED
@@ -1,7 +1,17 @@
1
- # v0.1.0
1
+ ### Development
2
+
3
+ [full diff](http://github.com/plexus/asset_packer/compare/v0.2.0...master)
4
+
5
+ ### v0.2.0
6
+
7
+ Make rewritten CSS links fully qualified
8
+
9
+ Bunch of small improvements
10
+
11
+ ### v0.1.0
2
12
 
3
13
  First major release after extraction from Slippery
4
14
 
5
15
  * command line and Hexp usage
6
16
  * support for img, stylesheet, script
7
- * taken out StandAlone to focus on Local
17
+ * taken out StandAlone to focus on Local
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- asset_packer (0.1.0)
5
- hexp (~> 0.3.3)
4
+ asset_packer (0.2.0)
5
+ hexp (~> 0.4.6)
6
6
  mime-types (~> 2.2)
7
7
 
8
8
  GEM
@@ -16,73 +16,79 @@ GEM
16
16
  abstract_type (~> 0.0.7)
17
17
  adamantium (~> 0.1)
18
18
  equalizer (~> 0.0.8)
19
- ast (1.1.0)
20
- concord (0.1.4)
21
- adamantium (~> 0.1)
22
- equalizer (~> 0.0.7)
19
+ ast (2.0.0)
20
+ concord (0.1.5)
21
+ adamantium (~> 0.2.0)
22
+ equalizer (~> 0.0.9)
23
23
  diff-lcs (1.2.5)
24
24
  equalizer (0.0.9)
25
- hexp (0.3.3)
25
+ hexp (0.4.6)
26
+ concord (~> 0.0)
26
27
  equalizer (~> 0.0)
27
- ice_nine (~> 0.9)
28
28
  nokogiri (~> 1.6)
29
- sass (~> 3.2.19)
30
- ice_nine (0.11.0)
31
- inflecto (0.0.2)
29
+ ice_nine (0.11.1)
32
30
  memoizable (0.4.2)
33
31
  thread_safe (~> 0.3, >= 0.3.1)
34
- mime-types (2.2)
35
- mini_portile (0.5.3)
36
- morpher (0.2.2)
32
+ mime-types (2.4.3)
33
+ mini_portile (0.6.2)
34
+ morpher (0.2.3)
37
35
  abstract_type (~> 0.0.7)
38
36
  adamantium (~> 0.2.0)
39
37
  anima (~> 0.2.0)
40
- ast (~> 1.1.0)
38
+ ast (~> 2.0.0)
41
39
  concord (~> 0.1.4)
42
40
  equalizer (~> 0.0.9)
43
41
  ice_nine (~> 0.11.0)
44
42
  procto (~> 0.0.2)
45
- mutant (0.5.10)
43
+ mutant (0.7.8)
46
44
  abstract_type (~> 0.0.7)
47
45
  adamantium (~> 0.2.0)
48
46
  anima (~> 0.2.0)
49
- concord (~> 0.1.4)
47
+ ast (~> 2.0)
48
+ concord (~> 0.1.5)
50
49
  diff-lcs (~> 1.2)
51
50
  equalizer (~> 0.0.9)
52
- ice_nine (~> 0.11.0)
53
- inflecto (~> 0.0.2)
51
+ ice_nine (~> 0.11.1)
54
52
  memoizable (~> 0.4.2)
55
- morpher (~> 0.2.1)
56
- parser (~> 2.1)
53
+ morpher (~> 0.2.3)
54
+ parallel (~> 1.3)
55
+ parser (~> 2.2.0.2)
57
56
  procto (~> 0.0.2)
58
- unparser (~> 0.1.10)
59
- mutant-rspec (0.5.10)
60
- mutant (~> 0.5.10)
61
- rspec-core (>= 2.14.1, <= 3.0.0.beta2)
62
- nokogiri (1.6.1)
63
- mini_portile (~> 0.5.0)
64
- parser (2.1.8)
65
- ast (~> 1.1)
66
- slop (~> 3.4, >= 3.4.5)
57
+ unparser (~> 0.2.2)
58
+ mutant-rspec (0.7.8)
59
+ mutant (~> 0.7.8)
60
+ rspec-core (>= 3.0.0, < 3.3.0)
61
+ nokogiri (1.6.6.2)
62
+ mini_portile (~> 0.6.0)
63
+ parallel (1.4.1)
64
+ parser (2.2.0.3)
65
+ ast (>= 1.1, < 3.0)
67
66
  procto (0.0.2)
68
- rake (10.3.1)
69
- rspec (2.14.1)
70
- rspec-core (~> 2.14.0)
71
- rspec-expectations (~> 2.14.0)
72
- rspec-mocks (~> 2.14.0)
73
- rspec-core (2.14.8)
74
- rspec-expectations (2.14.5)
75
- diff-lcs (>= 1.1.3, < 2.0)
76
- rspec-mocks (2.14.6)
77
- sass (3.2.19)
78
- slop (3.5.0)
79
- thread_safe (0.3.3)
80
- unparser (0.1.12)
67
+ rake (10.4.2)
68
+ rspec (3.2.0)
69
+ rspec-core (~> 3.2.0)
70
+ rspec-expectations (~> 3.2.0)
71
+ rspec-mocks (~> 3.2.0)
72
+ rspec-core (3.2.2)
73
+ rspec-support (~> 3.2.0)
74
+ rspec-expectations (3.2.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.2.0)
77
+ rspec-its (1.2.0)
78
+ rspec-core (>= 3.0.0)
79
+ rspec-expectations (>= 3.0.0)
80
+ rspec-mocks (3.2.1)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.2.0)
83
+ rspec-support (3.2.2)
84
+ thread_safe (0.3.5)
85
+ unparser (0.2.2)
81
86
  abstract_type (~> 0.0.7)
82
87
  adamantium (~> 0.2.0)
83
- concord (~> 0.1.4)
88
+ concord (~> 0.1.5)
89
+ diff-lcs (~> 1.2.5)
84
90
  equalizer (~> 0.0.9)
85
- parser (~> 2.1)
91
+ parser (~> 2.2.0.2)
86
92
  procto (~> 0.0.2)
87
93
 
88
94
  PLATFORMS
@@ -90,6 +96,7 @@ PLATFORMS
90
96
 
91
97
  DEPENDENCIES
92
98
  asset_packer!
93
- mutant-rspec (~> 0.5.10)
99
+ mutant-rspec
94
100
  rake (~> 10.2)
95
- rspec (~> 2.14)
101
+ rspec
102
+ rspec-its
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ gem.define
25
25
 
26
26
  desc "Push gem to rubygems.org"
27
27
  task :push => :gem do
28
- #sh "git tag v#{AssetPacker::VERSION}"
28
+ sh "git tag v#{AssetPacker::VERSION}"
29
29
  sh "git push --tags"
30
30
  sh "gem push pkg/asset_packer-#{AssetPacker::VERSION}.gem"
31
31
  end
data/asset_packer.gemspec CHANGED
@@ -20,10 +20,11 @@ Gem::Specification.new do |gem|
20
20
  gem.bindir = 'bin'
21
21
  gem.executables << 'asset_packer'
22
22
 
23
- gem.add_runtime_dependency 'hexp' , '~> 0.3.3'
23
+ gem.add_runtime_dependency 'hexp' , '~> 0.4.6'
24
24
  gem.add_runtime_dependency 'mime-types' , '~> 2.2'
25
25
 
26
26
  gem.add_development_dependency 'rake' , '~> 10.2'
27
- gem.add_development_dependency 'rspec' , '~> 2.14'
28
- gem.add_development_dependency 'mutant-rspec' , '~> 0.5.10'
27
+ gem.add_development_dependency 'rspec'
28
+ gem.add_development_dependency 'rspec-its'
29
+ gem.add_development_dependency 'mutant-rspec'
29
30
  end
@@ -0,0 +1,32 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect
4
+ all people who contribute through reporting issues, posting feature
5
+ requests, updating documentation, submitting pull requests or patches,
6
+ and other activities.
7
+
8
+ We are committed to making participation in this project a
9
+ harassment-free experience for everyone, regardless of level of
10
+ experience, gender, gender identity and expression, sexual
11
+ orientation, disability, personal appearance, body size, race, age, or
12
+ religion.
13
+
14
+ Examples of unacceptable behavior by participants include the use of
15
+ sexual language or imagery, derogatory comments or personal attacks,
16
+ trolling, public or private harassment, insults, or other
17
+ unprofessional conduct.
18
+
19
+ Project maintainers have the right and responsibility to remove, edit,
20
+ or reject comments, commits, code, wiki edits, issues, and other
21
+ contributions that are not aligned to this Code of Conduct. Project
22
+ maintainers who do not follow the Code of Conduct may be removed from
23
+ the project team.
24
+
25
+ Instances of abusive, harassing, or otherwise unacceptable behavior
26
+ may be reported by opening an issue or contacting one or more of the
27
+ project maintainers.
28
+
29
+ This Code of Conduct is adapted from the
30
+ [Contributor Covenant](http:contributor-covenant.org), version 1.0.0,
31
+ available at
32
+ [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
@@ -55,7 +55,7 @@ module AssetPacker
55
55
 
56
56
  def run
57
57
  asset_dir = outfile.dirname.join("#{outfile.basename(outfile.extname)}_assets")
58
- local = Processor::Local.new(infile, asset_dir, outfile)
58
+ local = Processor::Local.new(infile, asset_dir, outfile)
59
59
  doc = Hexp.parse(local.retrieve_asset(infile))
60
60
  File.write(outfile, local.(doc).to_html)
61
61
  end
@@ -9,10 +9,12 @@ module AssetPacker
9
9
  end
10
10
 
11
11
  def save_asset(uri, extension)
12
+ return uri if uri =~ /^data:/
12
13
  asset_dir.mkdir unless asset_dir.directory?
13
14
  content = retrieve_asset(uri)
15
+ content = yield(content) if block_given?
14
16
  digest = Digest::MD5.hexdigest(content)
15
- target = asset_dir.join(digest + '.' + extension)
17
+ target = asset_dir.join(extension ? digest + '.' + extension : digest)
16
18
  File.write(target, content) unless target.exist?
17
19
  target.relative_path_from(destination.dirname)
18
20
  end
@@ -38,7 +40,15 @@ module AssetPacker
38
40
  class Stylesheet < self
39
41
  def call(doc)
40
42
  doc.replace('link[rel=stylesheet]') do |link|
41
- link.attr(:href, save_asset(link[:href], 'css'))
43
+ link.attr(:href, save_asset(link[:href], 'css', &extract_css_links(link[:href])))
44
+ end
45
+ end
46
+
47
+ def extract_css_links(base_url)
48
+ ->(content) do
49
+ content.gsub(/url\(['"]?([^\)'"]*)['"]?\)/) {
50
+ "url(../#{ save_asset(URI.join(full_source_uri, base_url, $1), File.extname($1)[1..-1]) })"
51
+ }
42
52
  end
43
53
  end
44
54
  end
@@ -1,28 +1,42 @@
1
1
  module AssetPacker
2
2
  class Processor
3
- attr_reader :source_uri, :asset_dir, :destination
3
+ attr_reader :source_uri, :full_source_uri, :asset_dir, :destination
4
4
 
5
5
  # source_uri: location of the original document, used to retrieve relative URI's
6
6
  # asset_dir: location where assets will be stored
7
7
  # destination: file that will be generated, used to create relative URI's from
8
8
  def initialize(source_uri, asset_dir, destination)
9
- @source_uri = URI(source_uri)
10
- if @source_uri.relative?
11
- @source_uri = URI("file://#{Pathname(source_uri).expand_path}")
9
+ @source_uri = source_uri
10
+ @full_source_uri = URI(source_uri)
11
+ if @full_source_uri.relative?
12
+ source_file = Pathname(source_uri).expand_path
13
+ @full_source_uri = URI("file://#{source_file}")
14
+ @cache_dir = source_file.dirname.join('.asset_cache')
15
+ FileUtils.mkdir_p @cache_dir unless @cache_dir.exist?
12
16
  end
13
17
  @asset_dir = Pathname(asset_dir)
14
18
  @destination = Pathname(destination)
15
19
  end
16
20
 
17
21
  def retrieve_asset(uri)
18
- uri = URI.join(source_uri, uri)
19
- case
20
- when %w[http https].include?(uri.scheme)
21
- Net::HTTP.get(uri)
22
- when uri.scheme.eql?('file')
23
- File.read(uri.path)
22
+ uri = URI.join(full_source_uri, uri)
23
+ cache(uri) do
24
+ case
25
+ when %w[http https].include?(uri.scheme)
26
+ Net::HTTP.get(uri)
27
+ when uri.scheme.eql?('file')
28
+ File.read(uri.path)
29
+ end
24
30
  end
25
31
  end
26
32
 
33
+ def cache(uri)
34
+ return yield if @cache_dir.nil? || uri.scheme == 'file'
35
+ hash = Digest::SHA256.hexdigest(uri.to_s)
36
+ cache_path = @cache_dir.join(hash)
37
+ cache_path.write(yield) unless cache_path.exist?
38
+ cache_path.read || ''
39
+ end
40
+
27
41
  end
28
42
  end
@@ -1,3 +1,3 @@
1
1
  module AssetPacker
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/asset_packer.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'pathname'
2
2
  require 'net/http'
3
3
  require 'base64'
4
+ require 'digest'
4
5
  require 'optparse'
5
6
 
6
7
  require 'hexp'
@@ -5,22 +5,22 @@ describe AssetPacker::Processor do
5
5
 
6
6
  let(:fixture_pathname) { src_dir.join 'section.css' }
7
7
 
8
- its(:source_uri) { should eq URI("file://#{source_uri}") }
8
+ its(:full_source_uri) { should eq URI("file://#{source_uri}") }
9
9
 
10
10
  describe '#initialize' do
11
- let(:subject) { described_class.new('/source/file.html', '/asset_dir', '/dest.html') }
12
- its(:source_uri) { should eq URI('file:///source/file.html') }
11
+ let(:subject) { described_class.new('/tmp/source/file.html', '/asset_dir', '/dest.html') }
12
+ its(:full_source_uri) { should eq URI('file:///tmp/source/file.html') }
13
13
  its(:asset_dir) { should eq Pathname('/asset_dir') }
14
14
  its(:destination) { should eq Pathname('/dest.html') }
15
15
 
16
16
  context 'with absolute URI' do
17
17
  let(:subject) { described_class.new('http://source/file.html', '/asset_dir', '/dest.html') }
18
- its(:source_uri) { should eq URI('http://source/file.html') }
18
+ its(:full_source_uri) { should eq URI('http://source/file.html') }
19
19
  end
20
20
 
21
21
  context 'with a relative file name' do
22
22
  let(:subject) { described_class.new('foo/bar.html', '/asset_dir', 'dest.html') }
23
- its(:source_uri) { should eq URI("file://#{AssetPacker::ROOT.join('foo/bar.html')}") }
23
+ its(:full_source_uri) { should eq URI("file://#{AssetPacker::ROOT.join('foo/bar.html')}") }
24
24
  end
25
25
  end
26
26
 
@@ -63,7 +63,7 @@ describe AssetPacker::Processor do
63
63
 
64
64
  it 'should return nil' do
65
65
  expect(Net::HTTP).to_not receive(:get)
66
- expect(asset).to be_nil
66
+ expect(asset).to eql ""
67
67
  end
68
68
  end
69
69
  end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,8 @@ require 'fileutils'
6
6
  require 'asset_packer'
7
7
  require_relative 'shared'
8
8
 
9
+ require 'rspec/its'
10
+
9
11
  module FixtureHelpers
10
12
  def with_fixture(html_file, assets = [])
11
13
  subject(:processor) { described_class.new(source_uri.to_s, dst_dir.to_s, destination.to_s) }
metadata CHANGED
@@ -1,85 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_packer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arne Brasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-20 00:00:00.000000000 Z
11
+ date: 2015-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hexp
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.3
19
+ version: 0.4.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.3
26
+ version: 0.4.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mime-types
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '2.14'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '2.14'
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: mutant-rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ~>
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: 0.5.10
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ~>
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: 0.5.10
96
+ version: '0'
83
97
  description: Create an offline version of a HTML file.
84
98
  email:
85
99
  - arne@arnebrasseur.net
@@ -90,8 +104,8 @@ extra_rdoc_files:
90
104
  - README.md
91
105
  - LICENSE
92
106
  files:
93
- - .gitignore
94
- - .travis.yml
107
+ - ".gitignore"
108
+ - ".travis.yml"
95
109
  - Changelog.md
96
110
  - Gemfile
97
111
  - Gemfile.lock
@@ -100,6 +114,7 @@ files:
100
114
  - Rakefile
101
115
  - asset_packer.gemspec
102
116
  - bin/asset_packer
117
+ - code_of_conduct.md
103
118
  - lib/asset_packer.rb
104
119
  - lib/asset_packer/cli.rb
105
120
  - lib/asset_packer/processor.rb
@@ -134,17 +149,17 @@ require_paths:
134
149
  - lib
135
150
  required_ruby_version: !ruby/object:Gem::Requirement
136
151
  requirements:
137
- - - '>='
152
+ - - ">="
138
153
  - !ruby/object:Gem::Version
139
154
  version: '0'
140
155
  required_rubygems_version: !ruby/object:Gem::Requirement
141
156
  requirements:
142
- - - '>='
157
+ - - ">="
143
158
  - !ruby/object:Gem::Version
144
159
  version: '0'
145
160
  requirements: []
146
161
  rubyforge_project:
147
- rubygems_version: 2.0.14
162
+ rubygems_version: 2.4.5
148
163
  signing_key:
149
164
  specification_version: 4
150
165
  summary: Create an offline version of a HTML file.