jekyll-minibundle 1.0.0 → 1.1.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.
@@ -5,24 +5,28 @@ module Jekyll::Minibundle::Test
5
5
  class MiniStampTest < TestCase
6
6
  include FixtureConfig
7
7
 
8
- EXPECTED_ASSET_PATH = 'assets/screen-390be921ee0eff063817bb5ef2954300.css'
8
+ def test_asset_destination_path_has_no_stamp_in_development_mode
9
+ with_precompiled_site :development do
10
+ assert_equal STAMP_DESTINATION_PATH, find_css_path_from_index
11
+ end
12
+ end
9
13
 
10
- def test_asset_path_has_stamp
14
+ def test_asset_destination_path_has_stamp_in_production_mode
11
15
  with_precompiled_site :production do
12
- assert_equal EXPECTED_ASSET_PATH, find_css_path_from_index
16
+ assert_equal STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index
13
17
  end
14
18
  end
15
19
 
16
20
  def test_asset_file_is_copied_to_destination_dir
17
21
  with_precompiled_site :production do
18
- assert File.exists?(destination_path(EXPECTED_ASSET_PATH))
22
+ assert File.exists?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
19
23
  end
20
24
  end
21
25
 
22
26
  def test_asset_file_is_equal_to_source_file
23
27
  with_precompiled_site :production do
24
- source_contents = File.read site_fixture_path(CSS_STAMP_SOURCE_FILE)
25
- destination_contents = File.read destination_path(EXPECTED_ASSET_PATH)
28
+ source_contents = File.read site_fixture_path(STAMP_SOURCE_PATH)
29
+ destination_contents = File.read destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
26
30
  assert_equal source_contents, destination_contents
27
31
  end
28
32
  end
@@ -30,10 +34,10 @@ module Jekyll::Minibundle::Test
30
34
  def test_change_asset_file
31
35
  with_site do
32
36
  generate_site :production
33
- assert File.exists?(destination_path(EXPECTED_ASSET_PATH))
34
- File.write source_path(CSS_STAMP_SOURCE_FILE), 'h1 {}'
37
+ assert File.exists?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
38
+ File.write source_path(STAMP_SOURCE_PATH), 'h1 {}'
35
39
  generate_site :production
36
- refute File.exists?(destination_path(EXPECTED_ASSET_PATH))
40
+ refute File.exists?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
37
41
  expected_new_path = 'assets/screen-0f5dbd1e527a2bee267e85007b08d2a5.css'
38
42
  assert_equal expected_new_path, find_css_path_from_index
39
43
  assert File.exists?(destination_path(expected_new_path))
@@ -42,19 +46,35 @@ module Jekyll::Minibundle::Test
42
46
 
43
47
  def test_supports_relative_and_absolute_destination_paths
44
48
  with_site do
45
- expected_path = destination_path EXPECTED_ASSET_PATH
46
-
47
49
  generate_site :production
50
+ expected_path = destination_path STAMP_DESTINATION_FINGERPRINT_PATH
48
51
 
49
52
  assert File.exists?(expected_path)
50
- assert_equal EXPECTED_ASSET_PATH, find_css_path_from_index
53
+ assert_equal STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index
51
54
 
52
55
  find_and_gsub_in_file(source_path('index.html'), %r{assets/screen.css}, '/\0')
53
56
 
54
57
  generate_site :production
55
58
 
56
59
  assert File.exists?(expected_path)
57
- assert_equal "/#{EXPECTED_ASSET_PATH}", find_css_path_from_index
60
+ assert_equal "/#{STAMP_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index
61
+ end
62
+ end
63
+
64
+ def test_do_not_copy_source_when_other_files_change
65
+ with_site do
66
+ generate_site :production
67
+ expected_path = destination_path STAMP_DESTINATION_FINGERPRINT_PATH
68
+ org_mtime = mtime_of expected_path
69
+ ensure_file_mtime_changes { File.write source_path(JS_BUNDLE_SOURCE_DIR, 'dependency.js'), '(function() {})()' }
70
+ generate_site :production
71
+
72
+ assert_equal org_mtime, mtime_of(expected_path)
73
+
74
+ ensure_file_mtime_changes { FileUtils.touch 'index.html' }
75
+ generate_site :production
76
+
77
+ assert_equal org_mtime, mtime_of(expected_path)
58
78
  end
59
79
  end
60
80
 
@@ -1,11 +1,15 @@
1
1
  module Jekyll::Minibundle::Test
2
2
  module FixtureConfig
3
- CSS_STAMP_SOURCE_FILE = '_tmp/site.css'
3
+ STAMP_SOURCE_PATH = '_tmp/site.css'
4
+ STAMP_DESTINATION_PATH = 'assets/screen.css'
5
+ STAMP_DESTINATION_FINGERPRINT_PATH = 'assets/screen-390be921ee0eff063817bb5ef2954300.css'
4
6
 
5
- CSS_BUNDLE_DESTINATION_DIR = 'assets/site'
7
+ CSS_BUNDLE_DESTINATION_PATH = 'assets/site'
6
8
  CSS_BUNDLE_SOURCE_DIR = '_assets/styles'
9
+ EXPECTED_CSS_BUNDLE_PATH = CSS_BUNDLE_DESTINATION_PATH + '-b2e0ecc1c100effc2c7353caad20c327.css'
7
10
 
8
- JS_BUNDLE_DESTINATION_DIR = 'assets/site'
11
+ JS_BUNDLE_DESTINATION_PATH = 'assets/site'
9
12
  JS_BUNDLE_SOURCE_DIR = '_assets/scripts'
13
+ EXPECTED_JS_BUNDLE_PATH = JS_BUNDLE_DESTINATION_PATH + '-4782a1f67803038d4f8351051e67deb8.js'
10
14
  end
11
15
  end
@@ -33,6 +33,10 @@ module Jekyll::Minibundle::Test
33
33
  File.write file, new_content
34
34
  end
35
35
 
36
+ def mtime_of(path)
37
+ File.stat(path).mtime
38
+ end
39
+
36
40
  def with_env(env)
37
41
  org_env = {}
38
42
  env.each do |k, v|
@@ -57,12 +61,25 @@ module Jekyll::Minibundle::Test
57
61
  Dir.chdir(_get_precompiled_site(mode), &block)
58
62
  end
59
63
 
60
- def generate_site(mode)
64
+ def generate_site(mode, options = {})
61
65
  with_env 'JEKYLL_MINIBUNDLE_MODE' => mode.to_s do
62
- _generate_site Dir.pwd, '_site'
66
+ _generate_site _get_site_generation_test_options(options)
63
67
  end
64
68
  end
65
69
 
70
+ def ensure_file_mtime_changes(&block)
71
+ sleep 1.5
72
+ yield
73
+ end
74
+
75
+ def cmd_to_remove_comments_and_count
76
+ site_fixture_path('_bin/with_count') + ' count _bin/remove_comments'
77
+ end
78
+
79
+ def get_cmd_count
80
+ File.read('count').to_i
81
+ end
82
+
66
83
  private
67
84
 
68
85
  def _copy_fixture_site_dir(dir)
@@ -76,23 +93,37 @@ module Jekyll::Minibundle::Test
76
93
  dir = Dir.mktmpdir("jekyll-minibundle-test-precompiled-site-#{mode}-")
77
94
  at_exit do
78
95
  FileUtils.rm_rf dir
79
- puts "\nCleaned precompiled site for tests: #{dir}"
96
+ puts "\nCleaned precompiled site in #{mode} mode for tests: #{dir}"
80
97
  end
81
98
  Dir.chdir(dir) do
82
99
  _copy_fixture_site_dir Dir.pwd
83
100
  generate_site mode
84
101
  end
85
- puts "\nGenerated precompiled site in #{mode} mode for tests: #{dir}"
86
102
  dir
87
103
  end
88
104
  end
89
105
 
90
- def _generate_site(source, destination)
91
- options = {
92
- 'source' => source,
93
- 'destination' => destination
106
+ def _generate_site(test_options)
107
+ BundleFile.clear_cache if test_options[:clear_cache]
108
+
109
+ capture_io do
110
+ Jekyll::Site.new(Jekyll.configuration(TestCase.site_generation_jekyll_options)).process
111
+ end
112
+ end
113
+
114
+ def _get_site_generation_test_options(options)
115
+ TestCase.site_generation_test_options.merge options
116
+ end
117
+
118
+ def self.site_generation_test_options
119
+ { clear_cache: true }
120
+ end
121
+
122
+ def self.site_generation_jekyll_options
123
+ {
124
+ 'source' => Dir.pwd,
125
+ 'destination' => '_site'
94
126
  }
95
- capture_io { Jekyll::Site.new(Jekyll.configuration(options)).process }
96
127
  end
97
128
  end
98
129
  end
@@ -21,7 +21,7 @@ module Jekyll::Minibundle::Test
21
21
  def test_raise_exception_if_bundle_command_not_configured
22
22
  with_env 'JEKYLL_MINIBUNDLE_CMD_JS' => nil do
23
23
  err = assert_raises(RuntimeError) { make_bundle }
24
- assert_equal 'You need to set bundling command in $JEKYLL_MINIBUNDLE_CMD_JS', err.to_s
24
+ assert_equal 'You need to set command for minification in $JEKYLL_MINIBUNDLE_CMD_JS', err.to_s
25
25
  end
26
26
  end
27
27
 
@@ -0,0 +1,57 @@
1
+ require 'support/test_case'
2
+ require 'support/fixture_config'
3
+ require 'jekyll/minibundle/bundle_file'
4
+
5
+ module Jekyll::Minibundle::Test
6
+ class BundleFileTest < TestCase
7
+ include FixtureConfig
8
+
9
+ def test_consistent_fingerprint_in_file_and_markup
10
+ with_site do
11
+ with_env 'JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count do
12
+ bundle_file = BundleFile.new({
13
+ 'type' => :js,
14
+ 'site_dir' => '.',
15
+ 'source_dir' => JS_BUNDLE_SOURCE_DIR,
16
+ 'assets' => %w{dependency app},
17
+ 'destination_path' => JS_BUNDLE_DESTINATION_PATH,
18
+ 'attributes' => {}
19
+ })
20
+ source = source_path JS_BUNDLE_SOURCE_DIR, 'app.js'
21
+ old_destination = destination_path EXPECTED_JS_BUNDLE_PATH
22
+ org_markup, last_markup = nil
23
+
24
+ capture_io do
25
+ org_markup = bundle_file.markup
26
+ bundle_file.write '_site'
27
+ end
28
+
29
+ org_mtime = mtime_of old_destination
30
+
31
+ assert_equal 1, get_cmd_count
32
+
33
+ last_markup = bundle_file.markup
34
+ ensure_file_mtime_changes { File.write source, '(function() {})()' }
35
+ bundle_file.write '_site'
36
+
37
+ # preserve fingerprint and content seen in last markup phase
38
+ assert_equal org_markup, last_markup
39
+ assert_equal org_mtime, mtime_of(old_destination)
40
+ assert_equal 1, get_cmd_count
41
+
42
+ capture_io do
43
+ last_markup = bundle_file.markup
44
+ bundle_file.write '_site'
45
+ end
46
+
47
+ new_destination = destination_path 'assets/site-375a0b430b0c5555d0edd2205d26c04d.js'
48
+
49
+ # see updated fingerprint in the next round
50
+ refute_equal org_markup, last_markup
51
+ assert_operator mtime_of(new_destination), :>, org_mtime
52
+ assert_equal 2, get_cmd_count
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,42 @@
1
+ require 'support/test_case'
2
+ require 'support/fixture_config'
3
+ require 'jekyll/minibundle/stamp_file'
4
+
5
+ module Jekyll::Minibundle::Test
6
+ class StampFileTest < TestCase
7
+ include FixtureConfig
8
+
9
+ def test_consistent_fingerprint_in_file_and_markup
10
+ with_site do
11
+ basenamer = ->(base, ext, stamper) { "#{base}-#{stamper.call}#{ext}" }
12
+ stamp_file = StampFile.new(STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &basenamer)
13
+
14
+ source = source_path STAMP_SOURCE_PATH
15
+ old_destination = destination_path STAMP_DESTINATION_FINGERPRINT_PATH
16
+
17
+ org_markup = stamp_file.markup
18
+ stamp_file.write '_site'
19
+ org_mtime = mtime_of old_destination
20
+
21
+ last_markup = stamp_file.markup
22
+ ensure_file_mtime_changes { File.write source, 'h1 {}' }
23
+ stamp_file.write '_site'
24
+
25
+ # preserve fingerprint and content seen in last markup phase
26
+ assert_equal org_markup, last_markup
27
+ assert_equal org_mtime, mtime_of(old_destination)
28
+ assert_equal File.read(site_fixture_path(STAMP_SOURCE_PATH)), File.read(old_destination)
29
+
30
+ last_markup = stamp_file.markup
31
+ stamp_file.write '_site'
32
+
33
+ new_destination = destination_path 'assets/screen-0f5dbd1e527a2bee267e85007b08d2a5.css'
34
+
35
+ # see updated fingerprint in the next round
36
+ refute_equal org_markup, last_markup
37
+ assert_operator mtime_of(new_destination), :>, org_mtime
38
+ assert_equal File.read(source), File.read(new_destination)
39
+ end
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-minibundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tuomas Kareinen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-15 00:00:00.000000000 Z
11
+ date: 2013-02-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: jekyll
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: nokogiri
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -87,10 +78,12 @@ executables: []
87
78
  extensions: []
88
79
  extra_rdoc_files: []
89
80
  files:
90
- - History.md
91
- - License.txt
81
+ - CHANGELOG.md
82
+ - LICENSE.txt
83
+ - README.md
84
+ - RELEASING.txt
92
85
  - Rakefile
93
- - Readme.md
86
+ - jekyll-minibundle.gemspec
94
87
  - lib/jekyll/minibundle/asset_bundle.rb
95
88
  - lib/jekyll/minibundle/asset_file_operations.rb
96
89
  - lib/jekyll/minibundle/asset_file_paths.rb
@@ -99,6 +92,7 @@ files:
99
92
  - lib/jekyll/minibundle/bundle_file.rb
100
93
  - lib/jekyll/minibundle/development_file.rb
101
94
  - lib/jekyll/minibundle/development_file_collection.rb
95
+ - lib/jekyll/minibundle/environment.rb
102
96
  - lib/jekyll/minibundle/mini_bundle_block.rb
103
97
  - lib/jekyll/minibundle/mini_stamp_tag.rb
104
98
  - lib/jekyll/minibundle/stamp_file.rb
@@ -109,6 +103,7 @@ files:
109
103
  - test/fixture/site/_assets/styles/common.css
110
104
  - test/fixture/site/_assets/styles/reset.css
111
105
  - test/fixture/site/_bin/remove_comments
106
+ - test/fixture/site/_bin/with_count
112
107
  - test/fixture/site/_plugins/minibundle.rb
113
108
  - test/fixture/site/_tmp/site.css
114
109
  - test/fixture/site/index.html
@@ -119,9 +114,12 @@ files:
119
114
  - test/support/test_case.rb
120
115
  - test/unit/asset_bundle_test.rb
121
116
  - test/unit/asset_tag_markup_test.rb
117
+ - test/unit/bundle_file_test.rb
118
+ - test/unit/stamp_file_test.rb
122
119
  homepage: https://github.com/tkareine/jekyll-minibundle
123
120
  licenses:
124
121
  - MIT
122
+ metadata: {}
125
123
  post_install_message:
126
124
  rdoc_options:
127
125
  - --line-numbers
@@ -132,22 +130,20 @@ rdoc_options:
132
130
  require_paths:
133
131
  - lib
134
132
  required_ruby_version: !ruby/object:Gem::Requirement
135
- none: false
136
133
  requirements:
137
134
  - - ! '>='
138
135
  - !ruby/object:Gem::Version
139
- version: '0'
136
+ version: 1.9.3
140
137
  required_rubygems_version: !ruby/object:Gem::Requirement
141
- none: false
142
138
  requirements:
143
139
  - - ! '>='
144
140
  - !ruby/object:Gem::Version
145
141
  version: '0'
146
142
  requirements: []
147
143
  rubyforge_project:
148
- rubygems_version: 1.8.25
144
+ rubygems_version: 2.0.0
149
145
  signing_key:
150
- specification_version: 3
146
+ specification_version: 4
151
147
  summary: A minimalistic asset bundling plugin for Jekyll
152
148
  test_files:
153
149
  - test/fixture/site/_assets/scripts/app.js
@@ -155,6 +151,7 @@ test_files:
155
151
  - test/fixture/site/_assets/styles/common.css
156
152
  - test/fixture/site/_assets/styles/reset.css
157
153
  - test/fixture/site/_bin/remove_comments
154
+ - test/fixture/site/_bin/with_count
158
155
  - test/fixture/site/_plugins/minibundle.rb
159
156
  - test/fixture/site/_tmp/site.css
160
157
  - test/fixture/site/index.html
@@ -165,4 +162,6 @@ test_files:
165
162
  - test/support/test_case.rb
166
163
  - test/unit/asset_bundle_test.rb
167
164
  - test/unit/asset_tag_markup_test.rb
165
+ - test/unit/bundle_file_test.rb
166
+ - test/unit/stamp_file_test.rb
168
167
  has_rdoc: