tgfa-jekyll-assets 0.7.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +78 -0
  5. data/.travis.yml +9 -0
  6. data/.yardopts +1 -0
  7. data/Gemfile +15 -0
  8. data/Gemfile.jekyll-1.0 +2 -0
  9. data/Guardfile +8 -0
  10. data/HISTORY.md +202 -0
  11. data/LICENSE +22 -0
  12. data/README.md +569 -0
  13. data/Rakefile +9 -0
  14. data/lib/jekyll/assets_plugin/asset_path.rb +39 -0
  15. data/lib/jekyll/assets_plugin/configuration.rb +87 -0
  16. data/lib/jekyll/assets_plugin/environment.rb +62 -0
  17. data/lib/jekyll/assets_plugin/filters.rb +19 -0
  18. data/lib/jekyll/assets_plugin/patches/asset_patch.rb +68 -0
  19. data/lib/jekyll/assets_plugin/patches/bundled_asset_patch.rb +16 -0
  20. data/lib/jekyll/assets_plugin/patches/context_patch.rb +27 -0
  21. data/lib/jekyll/assets_plugin/patches/index_patch.rb +25 -0
  22. data/lib/jekyll/assets_plugin/patches/processed_asset_patch.rb +60 -0
  23. data/lib/jekyll/assets_plugin/patches/site_patch.rb +68 -0
  24. data/lib/jekyll/assets_plugin/patches.rb +1 -0
  25. data/lib/jekyll/assets_plugin/renderer.rb +47 -0
  26. data/lib/jekyll/assets_plugin/tag.rb +19 -0
  27. data/lib/jekyll/assets_plugin/version.rb +5 -0
  28. data/lib/jekyll/assets_plugin.rb +4 -0
  29. data/lib/jekyll-assets/bootstrap.rb +6 -0
  30. data/lib/jekyll-assets/bourbon.rb +4 -0
  31. data/lib/jekyll-assets/compass.rb +7 -0
  32. data/lib/jekyll-assets/font-awesome.rb +6 -0
  33. data/lib/jekyll-assets/neat.rb +4 -0
  34. data/lib/jekyll-assets.rb +2 -0
  35. data/spec/fixtures/.gitignore +2 -0
  36. data/spec/fixtures/_assets/app.css.erb +5 -0
  37. data/spec/fixtures/_assets/app.js +1 -0
  38. data/spec/fixtures/_assets/fonts/vapor.eot +0 -0
  39. data/spec/fixtures/_assets/fonts/vapor.svg +0 -0
  40. data/spec/fixtures/_assets/fonts/vapor.ttf +0 -0
  41. data/spec/fixtures/_assets/fonts/vapor.woff +0 -0
  42. data/spec/fixtures/_assets/lib/relative.css.scss +12 -0
  43. data/spec/fixtures/_assets/noise.png +0 -0
  44. data/spec/fixtures/_assets/should_be_blank.css.erb +1 -0
  45. data/spec/fixtures/_assets/should_fail.css.erb +1 -0
  46. data/spec/fixtures/_assets/vapor.css.scss +13 -0
  47. data/spec/fixtures/_assets/vapor.js +2 -0
  48. data/spec/fixtures/_assets/vendor/bourbon.css.sass +4 -0
  49. data/spec/fixtures/_assets/vendor/compass.css.sass +4 -0
  50. data/spec/fixtures/_assets/vendor/neat.css.sass +5 -0
  51. data/spec/fixtures/_assets/wowscript.js +0 -0
  52. data/spec/fixtures/_assets/wowstyle.css +0 -0
  53. data/spec/fixtures/_config.yml +2 -0
  54. data/spec/fixtures/_layouts/default.html +9 -0
  55. data/spec/fixtures/_posts/2012-10-19-hello-world.md +6 -0
  56. data/spec/fixtures/index.html +0 -0
  57. data/spec/lib/jekyll/assets_plugin/configuration_spec.rb +167 -0
  58. data/spec/lib/jekyll/assets_plugin/environment_spec.rb +22 -0
  59. data/spec/lib/jekyll/assets_plugin/filters_spec.rb +103 -0
  60. data/spec/lib/jekyll/assets_plugin/patches/site_patch_spec.rb +168 -0
  61. data/spec/lib/jekyll/assets_plugin/renderer_spec.rb +48 -0
  62. data/spec/lib/jekyll/assets_plugin/tag_spec.rb +103 -0
  63. data/spec/lib/jekyll-assets/bootstrap_spec.rb +8 -0
  64. data/spec/lib/jekyll-assets/bourbon_spec.rb +8 -0
  65. data/spec/lib/jekyll-assets/compass_spec.rb +8 -0
  66. data/spec/lib/jekyll-assets/font-awesome_spec.rb +8 -0
  67. data/spec/lib/jekyll-assets/neat_spec.rb +8 -0
  68. data/spec/spec_helper.rb +45 -0
  69. data/spec/support/fixtures_helpers.rb +7 -0
  70. data/tgfa-jekyll-assets.gemspec +41 -0
  71. metadata +322 -0
@@ -0,0 +1,62 @@
1
+ # stdlib
2
+ require "pathname"
3
+
4
+ # 3rd-party
5
+ require "sprockets"
6
+
7
+ module Jekyll
8
+ module AssetsPlugin
9
+ class Environment < Sprockets::Environment
10
+ class AssetNotFound < StandardError
11
+ def initialize(path)
12
+ super "Couldn't find file '#{path}'"
13
+ end
14
+ end
15
+
16
+ attr_reader :site
17
+
18
+ def initialize(site)
19
+ super site.source
20
+
21
+ @site = site
22
+
23
+ # append asset paths
24
+ site.assets_config.sources.each { |p| append_path p }
25
+
26
+ self.js_compressor = site.assets_config.js_compressor
27
+ self.css_compressor = site.assets_config.css_compressor
28
+
29
+ if site.assets_config.cache_assets?
30
+ self.cache = Sprockets::Cache::FileStore.new cache_path
31
+ end
32
+
33
+ # load css autoprefix post-processor
34
+ install_autoprefixer!
35
+
36
+ # reset cache if config changed
37
+ self.version = site.assets_config.marshal_dump
38
+
39
+ # bind jekyll and Sprockets context together
40
+ context_class.instance_variable_set :@site, site
41
+ context_class.send :include, Patches::ContextPatch
42
+ end
43
+
44
+ def cache_path
45
+ Pathname.new(@site.source).join @site.assets_config.cache_path
46
+ end
47
+
48
+ def find_asset(path, *args)
49
+ super || fail(AssetNotFound, path)
50
+ end
51
+
52
+ private
53
+
54
+ def install_autoprefixer!
55
+ require "autoprefixer-rails"
56
+ AutoprefixerRails.install(self)
57
+ rescue LoadError
58
+ nil
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,19 @@
1
+ # internal
2
+ require "jekyll/assets_plugin/renderer"
3
+
4
+ module Jekyll
5
+ module AssetsPlugin
6
+ module Filters
7
+ %w[asset asset_path image javascript stylesheet].each do |name|
8
+ module_eval <<-RUBY, __FILE__, __LINE__
9
+ def #{name} path # def stylesheet logical_path
10
+ r = Renderer.new @context, path # r = Renderer.new @context, path
11
+ r.render_#{name} # r.render_stylesheet
12
+ end # end
13
+ RUBY
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ Liquid::Template.register_filter Jekyll::AssetsPlugin::Filters
@@ -0,0 +1,68 @@
1
+ # 3rd-party
2
+ require "sprockets"
3
+
4
+ module Jekyll
5
+ module AssetsPlugin
6
+ module Patches
7
+ module AssetPatch
8
+ def self.included(base)
9
+ base.send :extend, ClassMethods
10
+ base.send :include, InstanceMethods
11
+ end
12
+
13
+ module ClassMethods
14
+ def mtimes
15
+ @mtimes ||= {}
16
+ end
17
+ end
18
+
19
+ module InstanceMethods
20
+ attr_reader :site
21
+
22
+ def jekyll_assets
23
+ []
24
+ end
25
+
26
+ def bundle!
27
+ site.bundle_asset! self if site
28
+ self
29
+ end
30
+
31
+ def destination(dest)
32
+ File.join dest, site.assets_config.dirname, filename
33
+ end
34
+
35
+ def filename
36
+ case cachebust = site.assets_config.cachebust
37
+ when :none, :soft then logical_path
38
+ when :hard then digest_path
39
+ else fail "Unknown cachebust strategy: #{cachebust.inspect}"
40
+ end
41
+ end
42
+
43
+ def modified?
44
+ self.class.mtimes[pathname.to_s] != mtime.to_i
45
+ end
46
+
47
+ def write(dest)
48
+ dest_path = destination dest
49
+
50
+ return false if File.exist?(dest_path) && !modified?
51
+ self.class.mtimes[pathname.to_s] = mtime.to_i
52
+
53
+ write_to dest_path
54
+ write_to "#{dest_path}.gz" if gzip?
55
+
56
+ true
57
+ end
58
+
59
+ def gzip?
60
+ site.assets_config.gzip.include? content_type
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ Sprockets::Asset.send :include, Jekyll::AssetsPlugin::Patches::AssetPatch
@@ -0,0 +1,16 @@
1
+ # 3rd-party
2
+ require "sprockets"
3
+
4
+ module Jekyll
5
+ module AssetsPlugin
6
+ module Patches
7
+ module BundledAssetPatch
8
+ def jekyll_assets
9
+ @processed_asset.jekyll_assets
10
+ end
11
+
12
+ ::Sprockets::BundledAsset.send :include, self
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ # stdlib
2
+ require "set"
3
+
4
+ module Jekyll
5
+ module AssetsPlugin
6
+ module Patches
7
+ module ContextPatch
8
+ def site
9
+ self.class.instance_variable_get :@site
10
+ end
11
+
12
+ def jekyll_assets
13
+ @jekyll_assets ||= Set.new
14
+ end
15
+
16
+ def asset_path(pathname, *args)
17
+ return "" if pathname.to_s.strip.empty?
18
+ asset = resolve(pathname.to_s[/^[^#?]+/]).to_s
19
+ jekyll_assets << asset
20
+ (site.asset_path asset, *args) + (pathname.to_s[/[#?].+/] || "")
21
+ rescue Sprockets::FileNotFound
22
+ raise Environment::AssetNotFound, pathname
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # 3rd-party
2
+ require "sprockets"
3
+
4
+ module Jekyll
5
+ module AssetsPlugin
6
+ module Patches
7
+ module IndexPatch
8
+ def self.included(base)
9
+ base.class_eval do
10
+ alias_method :__orig_find_asset, :find_asset
11
+ alias_method :find_asset, :__wrap_find_asset
12
+ end
13
+ end
14
+
15
+ def __wrap_find_asset(path, options = {})
16
+ __orig_find_asset(path, options).tap do |asset|
17
+ asset.instance_variable_set :@site, @environment.site if asset
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ Sprockets::Index.send :include, Jekyll::AssetsPlugin::Patches::IndexPatch
@@ -0,0 +1,60 @@
1
+ # stdlib
2
+ require "set"
3
+
4
+ # 3rd-party
5
+ require "sprockets"
6
+
7
+ module Jekyll
8
+ module AssetsPlugin
9
+ module Patches
10
+ module ProcessedAssetPatch
11
+ def self.included(base)
12
+ base.class_eval do
13
+ attr_reader :jekyll_assets
14
+
15
+ alias_method :__orig_build_dependency_paths,
16
+ :build_dependency_paths
17
+
18
+ alias_method :build_dependency_paths,
19
+ :__wrap_build_dependency_paths
20
+
21
+ alias_method :__orig_init_with, :init_with
22
+ alias_method :init_with, :__wrap_init_with
23
+
24
+ alias_method :__orig_encode_with, :encode_with
25
+ alias_method :encode_with, :__wrap_encode_with
26
+ end
27
+ end
28
+
29
+ def __wrap_build_dependency_paths(environment, context)
30
+ @jekyll_assets = Set.new
31
+
32
+ context.jekyll_assets.each do |path|
33
+ @jekyll_assets << path
34
+ environment.find_asset(path)
35
+ .jekyll_assets.each { |p| @jekyll_assets << p }
36
+ end
37
+
38
+ __orig_build_dependency_paths environment, context
39
+ end
40
+
41
+ def __wrap_init_with(environment, coder)
42
+ __orig_init_with environment, coder
43
+
44
+ @jekyll_assets = Set.new coder["jekyll_assets"]
45
+ .map { |p| expand_root_path(p) }
46
+ end
47
+
48
+ def __wrap_encode_with(coder)
49
+ __orig_encode_with coder
50
+
51
+ coder["jekyll_assets"] = jekyll_assets.map do |path|
52
+ relativize_root_path path
53
+ end
54
+ end
55
+
56
+ ::Sprockets::ProcessedAsset.send :include, self
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,68 @@
1
+ # stdlib
2
+ require "digest/md5"
3
+
4
+ # 3rd-party
5
+ require "jekyll"
6
+
7
+ # internal
8
+ require "jekyll/assets_plugin/configuration"
9
+ require "jekyll/assets_plugin/environment"
10
+ require "jekyll/assets_plugin/asset_path"
11
+
12
+ module Jekyll
13
+ module AssetsPlugin
14
+ module Patches
15
+ module SitePatch
16
+ def self.included(base)
17
+ base.class_eval do
18
+ alias_method :__orig_write, :write
19
+ alias_method :write, :__wrap_write
20
+ end
21
+ end
22
+
23
+ def assets_config
24
+ @assets_config ||= Configuration.new(config["assets"] || {})
25
+ end
26
+
27
+ def assets
28
+ @assets ||= Environment.new self
29
+ end
30
+
31
+ def asset_files
32
+ @asset_files ||= []
33
+ end
34
+
35
+ def asset_path(pathname, *args)
36
+ pathname, _, anchor = pathname.rpartition "#" if pathname["#"]
37
+ pathname, _, query = pathname.rpartition "?" if pathname["?"]
38
+
39
+ asset_path = AssetPath.new assets[pathname, *args]
40
+ asset_path.anchor = anchor
41
+ asset_path.query = query
42
+
43
+ asset_path.to_s
44
+ end
45
+
46
+ def bundle_asset!(asset)
47
+ return if asset_files.include? asset
48
+
49
+ asset_files << asset
50
+ asset.jekyll_assets.each { |path| bundle_asset! assets[path] }
51
+ end
52
+
53
+ def __wrap_write
54
+ static_files.push(*asset_files).uniq! do |asset|
55
+ case hash = asset.hash
56
+ when Fixnum then hash
57
+ else Digest::MD5.new.update(hash.to_s).hash
58
+ end
59
+ end
60
+
61
+ __orig_write
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ Jekyll::Site.send :include, Jekyll::AssetsPlugin::Patches::SitePatch
@@ -0,0 +1 @@
1
+ Dir[File.join File.dirname(__FILE__), "patches/**/*.rb"].each { |f| require f }
@@ -0,0 +1,47 @@
1
+ module Jekyll
2
+ module AssetsPlugin
3
+ class Renderer
4
+ STYLESHEET = '<link rel="stylesheet" href="%s">'
5
+ JAVASCRIPT = '<script src="%s"></script>'
6
+ IMAGE = '<img src="%s">'
7
+
8
+ def initialize(context, logical_path)
9
+ @site = context.registers[:site]
10
+ @path = logical_path.strip
11
+ end
12
+
13
+ def render_asset
14
+ @site.assets[@path].to_s
15
+ end
16
+
17
+ def render_asset_path
18
+ @site.asset_path @path
19
+ end
20
+
21
+ def render_javascript
22
+ @path << ".js" if File.extname(@path).empty?
23
+ render_tag JAVASCRIPT
24
+ end
25
+
26
+ def render_stylesheet
27
+ @path << ".css" if File.extname(@path).empty?
28
+ render_tag STYLESHEET
29
+ end
30
+
31
+ def render_image
32
+ render_tag IMAGE
33
+ end
34
+
35
+ protected
36
+
37
+ def render_tag(template)
38
+ asset = @site.assets[@path]
39
+ tags = (@site.assets_config.debug ? asset.to_a : [asset]).map do |a|
40
+ format template, AssetPath.new(a).to_s
41
+ end
42
+
43
+ tags.join "\n"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ # 3rd-party
2
+ require "liquid"
3
+
4
+ # internal
5
+ require "jekyll/assets_plugin/renderer"
6
+
7
+ module Jekyll
8
+ module AssetsPlugin
9
+ class Tag < Liquid::Tag
10
+ def render(context)
11
+ Renderer.new(context, @markup).send :"render_#{@tag_name}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ %w[asset asset_path image javascript stylesheet].each do |tag|
18
+ Liquid::Template.register_tag tag, Jekyll::AssetsPlugin::Tag
19
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module AssetsPlugin
3
+ VERSION = "0.7.9.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "jekyll/assets_plugin/patches"
2
+ require "jekyll/assets_plugin/filters"
3
+ require "jekyll/assets_plugin/tag"
4
+ require "jekyll/assets_plugin/version"
@@ -0,0 +1,6 @@
1
+ require "sprockets"
2
+
3
+ bootstrap = Gem::Specification.find_by_name("bootstrap-sass").gem_dir
4
+ %w[fonts javascripts stylesheets].each do |asset|
5
+ Sprockets.append_path File.join(bootstrap, "vendor", "assets", asset)
6
+ end
@@ -0,0 +1,4 @@
1
+ require "sprockets"
2
+
3
+ bourbon_root = Gem::Specification.find_by_name("bourbon").gem_dir
4
+ Sprockets.append_path File.join(bourbon_root, "app", "assets", "stylesheets")
@@ -0,0 +1,7 @@
1
+ require "compass"
2
+ require "sprockets"
3
+
4
+ Compass::Frameworks::ALL.each do |fw|
5
+ path = fw.stylesheets_directory
6
+ Sprockets.append_path path if path
7
+ end
@@ -0,0 +1,6 @@
1
+ require "sprockets"
2
+
3
+ fa = Gem::Specification.find_by_name("font-awesome-sass").gem_dir
4
+ %w[fonts stylesheets].each do |asset|
5
+ Sprockets.append_path File.join(fa, "vendor", "assets", asset)
6
+ end
@@ -0,0 +1,4 @@
1
+ require "sprockets"
2
+
3
+ neat_root = Gem::Specification.find_by_name("neat").gem_dir
4
+ Sprockets.append_path File.join(neat_root, "app", "assets", "stylesheets")
@@ -0,0 +1,2 @@
1
+ # rubocop: disable FileName
2
+ require "jekyll/assets_plugin"
@@ -0,0 +1,2 @@
1
+ _site/
2
+ .jekyll-assets-cache
@@ -0,0 +1,5 @@
1
+ /**
2
+ *= require vapor
3
+ */
4
+
5
+ body { background-image: url(<%= image_path 'noise.png' %>) }
@@ -0,0 +1 @@
1
+ //= require vapor
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ /* copy of vapor css framework to test relative asset inclusion*/
2
+
3
+ @font-face {
4
+ font-family: 'Vapor';
5
+ src: url(font_path('../fonts/vapor.eot'));
6
+ src: url(font_path('../fonts/vapor.eot?#iefix')) format("embedded-opentype"),
7
+ url(font_path('../fonts/vapor.woff')) format("woff"),
8
+ url(font_path('../fonts/vapor.ttf')) format("truetype"),
9
+ url(font_path('../fonts/vapor.svg#iefix')) format("svg");
10
+ font-weight: normal;
11
+ font-style: normal;
12
+ }
Binary file
@@ -0,0 +1 @@
1
+ body { background-image: url(<%= image_path '' %>) }
@@ -0,0 +1 @@
1
+ body { background-image: url(<%= image_path 'not-found.png' %>) }
@@ -0,0 +1,13 @@
1
+ //= require wowstyle
2
+ /* vapor css framework */
3
+
4
+ @font-face {
5
+ font-family: 'Vapor';
6
+ src: url(font_path('fonts/vapor.eot'));
7
+ src: url(font_path('fonts/vapor.eot?#iefix')) format("embedded-opentype"),
8
+ url(font_path('fonts/vapor.woff')) format("woff"),
9
+ url(font_path('fonts/vapor.ttf')) format("truetype"),
10
+ url(font_path('fonts/vapor.svg#iefix')) format("svg");
11
+ font-weight: normal;
12
+ font-style: normal;
13
+ }
@@ -0,0 +1,2 @@
1
+ //= require wowscript
2
+ /* vapor js framework */
@@ -0,0 +1,4 @@
1
+ @import "bourbon"
2
+
3
+ .photo
4
+ @include linear-gradient(#1e5799, #2989d8)
@@ -0,0 +1,4 @@
1
+ @import "compass"
2
+
3
+ .photo
4
+ @include background-image(linear-gradient(#1e5799, #2989d8))
@@ -0,0 +1,5 @@
1
+ @import "bourbon"
2
+ @import "neat"
3
+
4
+ .container
5
+ @include outer-container
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ assets:
2
+ sources: [ _assets ]
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <title>jekyll-assets</title>
4
+ {% stylesheet app %}
5
+ </head>
6
+ <body>
7
+ {{ content }}
8
+ </body>
9
+ </html>
@@ -0,0 +1,6 @@
1
+ ---
2
+ layout: default
3
+ title: Jekyll meets assets pipeline
4
+ ---
5
+
6
+ Assets pipelines for Jekyll.
File without changes