alexius_css_asset_tagger 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzA1MmJkMzQ3ZjZkYTk5ZGYyMzYzZDk3NDU3NDI4MmZlZWE5M2I2Ng==
5
+ data.tar.gz: !binary |-
6
+ ZWM3OTkwMjM3MmE3MzE1NzA2NzRkZTE4N2NkOTNiOTY4MGMzY2M2Yw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWU3MDQwMWE2MzZmNGRjZThiZGE4MTI3ZjIyYjdmOGI1NmRmMzc5ODc5ODdm
10
+ ODY5NTdhNGEwMzNkYzU4OGZlMjkzNDcyMDQ0YmMzMDQxZmQ1NzNhNjYyYzAw
11
+ ZGRiNTJlNmE3MTIzZmNmYTY4OTdkNzVlMjc2NGZmNGM3MTRjYzk=
12
+ data.tar.gz: !binary |-
13
+ MjI5MTExY2FiMGVmMThmMDQ5Nzg2YmY1ZTViNGY2MDc5MjljZGYzNzY2ZGJh
14
+ NDVlYTBhZDVkZDQ5YTc5ODU5NGJiMWQwMzdlZjRiYzdhZTFmYjFiMTI1Njc2
15
+ NWUxNDhlZGVmODc1YTcxNTY0YTgwODAyNTIzMmM1NzliNGE4MmE=
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Redline Software Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # CssAssetTagger
2
+
3
+ Adds asset query strings to assets found in css files. This gem originated as a rails plugin well before the asset pipeline was part of rails. This plugin is still useful in Rails 3.1+ apps though if the asset pipeline is not enabled.
4
+
5
+ ## Install
6
+
7
+ In your Gemfile:
8
+ `gem 'css_asset_tagger'`
9
+
10
+ ## Example
11
+
12
+ Simply install the plugin and css files will be updated to include asset tags for any found assets.
13
+
14
+ before:
15
+ `background: url("/images/background.png") repeat-x scroll 0 0 #ffffff;`
16
+
17
+ after:
18
+ `background: url(/images/background.png?1296473764) repeat-x scroll 0 0 #ffffff;`
19
+
20
+ To modify the plugins behaviour, add an initializer file to config/initializers
21
+
22
+ * __perform_tagging__ - Flag to determine if the css files should be modified with asset tags.
23
+ Defaults to tag in production only.
24
+ * __css_paths__ - An array of css stylesheet paths. Defaults to the main stylesheets path.
25
+ Defaults to ["#{Rails.root}/public/stylesheets"]
26
+ * __asset_path__ - The main asset path to be used when looking for assets with absolute file references.
27
+ Defaults to Rails.root.join('public')
28
+ * __show_warnings__ - Set to true to see warnings for assets that can't be found on the filesystem or false to not show the warnings.
29
+ Defaults to showing warnings in dev mode only.
30
+
31
+ ex. config/initializers/css_tagger_options.rb
32
+
33
+ require 'css_asset_tagger_options'
34
+
35
+ CssAssetTaggerOptions.setup do |config|
36
+ config.perform_tagging = true
37
+ end
38
+
39
+ Copyright (c) 2009-2013 Redline Software Inc., released under the MIT license
@@ -0,0 +1,42 @@
1
+ class CssAssetTagger
2
+ def self.tag(paths, logger = nil)
3
+ logger ||= Logger.new($stderr)
4
+
5
+ paths.each do |path|
6
+ files = Dir.glob(File.join(path, '**/*.css'))
7
+ for file in files
8
+ css = File.read file
9
+ res = css.gsub!(/url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)/mi) do |s|
10
+ # $1 is the double quoted string, $2 is single quoted, $3 is no quotes
11
+ uri = ($1 || $2 || $3).to_s.strip
12
+
13
+ # if the uri appears to begin with a protocol then the asset isn't on the local filesystem
14
+ # or if query string appears to exist already, the uri is returned as is
15
+ # or if uri contains embedded file, like base 64 ecoded image
16
+ if uri =~ /[a-z]+:\/\//i || uri =~ /(\?|&)\d{10}/ || uri =~ /^data:/i
17
+ "url(#{uri})"
18
+ else
19
+ # if the first char is a / then get the path of the file with respect to the absolute path of the asset files
20
+ # otherwise get the path relative to the current file
21
+ path = (uri.chars.first == '/' ? "#{CssAssetTaggerOptions.asset_path}#{uri}" : "#{File.dirname(file)}/#{uri}")
22
+
23
+ begin
24
+ # construct the uri with the associated asset query string
25
+ sep = (uri =~ /\?/).nil? ? '?' : '&'
26
+ "url(#{uri}#{sep}#{File.stat(path).mtime.to_i})"
27
+ rescue Errno::ENOENT
28
+ # the asset can't be found, so return the uri as is
29
+ logger.warn "CssAssetTagger: #{path} referenced from #{file} cannot be found." if CssAssetTaggerOptions.show_warnings
30
+ "url(#{uri})"
31
+ end
32
+ end
33
+ end
34
+
35
+ # write the new contents of the file out if asset tags were added
36
+ File.open(file, 'w'){|f| f.puts css} unless res.nil?
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ require 'css_asset_tagger/railtie' if defined?(Rails)
@@ -0,0 +1,13 @@
1
+ require 'rails/railtie'
2
+
3
+ module CssAssetTaggerOptions
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ Dir[File.expand_path('../../tasks/*.rake', __FILE__)].each { |f| load f }
7
+ end
8
+
9
+ config.to_prepare do
10
+ CssAssetTagger.tag(CssAssetTaggerOptions.css_paths) if CssAssetTaggerOptions.perform_tagging
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module CssAssetTaggerOptions
2
+ VERSION = '1.1'.freeze
3
+ end
@@ -0,0 +1,14 @@
1
+ module CssAssetTaggerOptions
2
+ mattr_accessor :perform_tagging, :css_paths, :asset_path, :show_warnings
3
+
4
+ if defined?(Rails)
5
+ @@perform_tagging = Rails.env.production?
6
+ @@css_paths = %W(#{Rails.root}/public/stylesheets)
7
+ @@asset_path = Rails.root.join('public')
8
+ @@show_warnings = Rails.env.development?
9
+ end
10
+
11
+ def self.setup
12
+ yield self
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'css_asset_tagger'
2
+ require 'css_asset_tagger_options'
3
+
4
+ namespace :css_asset_tagger do
5
+ desc "Add asset timestamps to assets found in the project stylesheets"
6
+ task :tag do
7
+ CssAssetTagger.tag CssAssetTaggerOptions.css_paths
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+
3
+ require 'test/unit'
4
+ require 'active_support/all'
5
+
6
+ require 'css_asset_tagger'
7
+ require 'css_asset_tagger_options'
8
+
9
+ class CssAssetTaggerTest < Test::Unit::TestCase
10
+ ASSET_PATH = File.dirname(__FILE__)+'/assets'
11
+ TEST_STYLESHEET = ASSET_PATH+'/stylesheets/test.css'
12
+
13
+ def setup
14
+ CssAssetTaggerOptions.perform_tagging = true
15
+ CssAssetTaggerOptions.asset_path = [ASSET_PATH]
16
+ FileUtils.cp TEST_STYLESHEET+'.template', TEST_STYLESHEET
17
+ end
18
+
19
+ def teardown
20
+ FileUtils.rm TEST_STYLESHEET
21
+ end
22
+
23
+ def test_this_plugin
24
+ # TODO capture the warnings and test for them
25
+ # how is this done?
26
+ l = Logger.new STDOUT
27
+ l.level = Logger::ERROR
28
+
29
+ CssAssetTagger.tag [ASSET_PATH+'/stylesheets'], l
30
+
31
+ # set the timestamps for the relative and absolute images
32
+ abs_time = File.stat(ASSET_PATH+'/images/test.png').mtime.to_i
33
+ rel_time = File.stat(ASSET_PATH+'/stylesheets/images/test.png').mtime.to_i
34
+
35
+ assert_equal ERB.new(File.read(TEST_STYLESHEET+'.expected')).result(self.send(:binding)).to_s, File.read(TEST_STYLESHEET).to_s
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alexius_css_asset_tagger
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kaspick
8
+ - Alexey Suhoviy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '3.0'
28
+ description: Tags assets in Rails app css files with asset query strings.
29
+ email: contact@plataformatec.com.br
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - lib/css_asset_tagger/railtie.rb
37
+ - lib/css_asset_tagger/version.rb
38
+ - lib/css_asset_tagger.rb
39
+ - lib/css_asset_tagger_options.rb
40
+ - lib/tasks/css_asset_tagger_tasks.rake
41
+ - test/css_asset_tagger_test.rb
42
+ homepage: https://github.com/redlinesoftware/css_asset_tagger
43
+ licenses: []
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.1.3
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Tags assets in Rails app css files with asset query strings.
65
+ test_files:
66
+ - test/css_asset_tagger_test.rb
67
+ has_rdoc: