juicer-rails 0.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.
- data/.gitignore +21 -0
- data/CHANGELOG.rdoc +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +62 -0
- data/Rakefile +2 -0
- data/init.rb +1 -0
- data/juicer-rails.gemspec +24 -0
- data/lib/juicer-rails.rb +42 -0
- data/lib/juicer-rails/collection.rb +110 -0
- data/lib/juicer-rails/helper.rb +15 -0
- data/lib/juicer-rails/railtie.rb +16 -0
- data/lib/juicer-rails/version.rb +3 -0
- data/test/helper.rb +10 -0
- data/test/test_juicer-rails.rb +7 -0
- metadata +101 -0
data/.gitignore
ADDED
data/CHANGELOG.rdoc
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Michał Łomnicki
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= juicer-rails
|
2
|
+
|
3
|
+
Rails helper for Juicer - excellent asset packaging tool.
|
4
|
+
|
5
|
+
https://github.com/cjohansen/juicer
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
Create config/assets.yml file
|
10
|
+
|
11
|
+
js:
|
12
|
+
common:
|
13
|
+
- 'public/javascripts/jquery/jquery.js'
|
14
|
+
- 'public/javascripts/common.js'
|
15
|
+
myapp:
|
16
|
+
- 'public/javascripts/application.js'
|
17
|
+
- 'public/javascripts/dashboard.js'
|
18
|
+
|
19
|
+
css:
|
20
|
+
myapp:
|
21
|
+
- 'public/stylesheets/application.css'
|
22
|
+
- 'public/stylesheets/dialogs.css'
|
23
|
+
|
24
|
+
juicer-rails provides 2 helper methods
|
25
|
+
* merged_javascripts - includes merged javascript assets
|
26
|
+
* merged_stylesheets - includes merged and cache-friendly stylesheet assets
|
27
|
+
|
28
|
+
Include merged assets in your layout
|
29
|
+
|
30
|
+
<head>
|
31
|
+
...
|
32
|
+
<%= merged_javascripts :common %>
|
33
|
+
<%= merged_javascripts :myapp %>
|
34
|
+
<%= merged_stylesheets :myapp %>
|
35
|
+
|
36
|
+
</head>
|
37
|
+
|
38
|
+
Please note that assets will be compiled only in production environemnt unless
|
39
|
+
<tt>always_compile</tt> options is set.
|
40
|
+
|
41
|
+
== Configuration
|
42
|
+
|
43
|
+
Create config/initializers/juicer-rails.rb
|
44
|
+
|
45
|
+
JuicerRails.setup do |config|
|
46
|
+
# config.always_compile = true
|
47
|
+
|
48
|
+
# add more options here
|
49
|
+
end
|
50
|
+
|
51
|
+
Available options are:
|
52
|
+
|
53
|
+
* config_file - path of confiugration file. default: config/assets.yml
|
54
|
+
* config - configuration in YAML format. default: content of config_file
|
55
|
+
* environemnt - current environment name. default: Rails.env
|
56
|
+
* compile_environments - which environments triggers compiling assets. default: production
|
57
|
+
* always_compile - always compile assets, no matter the environemnt. default: false
|
58
|
+
* compiled_assets_directory - subdirectory of public directory where compiled assets are stored. default: assets
|
59
|
+
|
60
|
+
== Copyright
|
61
|
+
|
62
|
+
Copyright (c) 2010 Michał Łomnicki. See LICENSE for details.
|
data/Rakefile
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "juicer-rails"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "juicer-rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "juicer-rails"
|
7
|
+
s.version = JuicerRails::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Michał Łomnicki"]
|
10
|
+
s.email = ["michal.lomnicki@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/mlomnicki/juicer-rails"
|
12
|
+
s.summary = "Rails helpers for Juicer"
|
13
|
+
s.description = "Juicer-rails adds helpers for easy embedding juicer-packaged assets"
|
14
|
+
|
15
|
+
s.rubyforge_project = "juicer-rails"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency("juicer", "~> 1.0")
|
23
|
+
s.add_dependency("actionpack", ">= 2.1")
|
24
|
+
end
|
data/lib/juicer-rails.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'juicer-rails/version'
|
2
|
+
require 'juicer-rails/helper'
|
3
|
+
require 'juicer-rails/railtie' if defined?(Rails::Railtie)
|
4
|
+
|
5
|
+
module JuicerRails
|
6
|
+
|
7
|
+
# location of configuration files
|
8
|
+
mattr_accessor :config_file
|
9
|
+
# Rails 3 set this with Railtie. Rails.root is nil at this stage
|
10
|
+
# Rails 2 has Rails.root defined so we can use it
|
11
|
+
@@config_file = Rails.root.join('config/assets.yml') if Rails.root
|
12
|
+
|
13
|
+
mattr_accessor :config
|
14
|
+
@@config = YAML.load_file(config_file) if config_file
|
15
|
+
|
16
|
+
# Current environment
|
17
|
+
mattr_accessor :environment
|
18
|
+
@@environment = Rails.env
|
19
|
+
|
20
|
+
# Which environments triggers assets compilations
|
21
|
+
mattr_accessor :compile_environments
|
22
|
+
@@compile_environments = %w[production]
|
23
|
+
|
24
|
+
# Always compile assets
|
25
|
+
mattr_accessor :always_compile
|
26
|
+
@@always_compile = false
|
27
|
+
|
28
|
+
# relative path from RAILS_ROOT/public where compiled assets are stored
|
29
|
+
mattr_accessor :compiled_assets_directory
|
30
|
+
@@compiled_assets_directory = 'assets'
|
31
|
+
|
32
|
+
def self.perform_compilation?
|
33
|
+
always_compile || compile_environments.include?(environment)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.setup
|
37
|
+
yield self
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
ActionView::Base.send(:include, Juicer::Helper)
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'juicer'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class Juicer::Collection
|
5
|
+
|
6
|
+
class << self
|
7
|
+
extend ActiveSupport::Memoizable
|
8
|
+
|
9
|
+
def dispatch(key, type)
|
10
|
+
if JuicerRails.perform_compilation?
|
11
|
+
compile(key, type)
|
12
|
+
else
|
13
|
+
embed_standalone(key, type)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def compile(key, type)
|
18
|
+
self.new(key, type).compile
|
19
|
+
destination_compiled_path(key, type).to_s
|
20
|
+
end
|
21
|
+
memoize :compile
|
22
|
+
|
23
|
+
# Embeds each asset as standalone file.
|
24
|
+
# The best mode for development purposes. No merging occurs
|
25
|
+
def embed_standalone(key, type)
|
26
|
+
dir = case type.to_s
|
27
|
+
when 'js' then 'javascripts'
|
28
|
+
when 'css' then 'stylesheets'
|
29
|
+
end
|
30
|
+
new(key, type).paths.collect { |p| Rails.root.join(p).relative_path_from(public_path.join(dir)).to_s }
|
31
|
+
end
|
32
|
+
|
33
|
+
def compiled_directory
|
34
|
+
public_path.join(JuicerRails.compiled_assets_directory)
|
35
|
+
end
|
36
|
+
|
37
|
+
def compiled_path(key, type)
|
38
|
+
compiled_directory.join("#{key}.#{type}")
|
39
|
+
end
|
40
|
+
|
41
|
+
def relative_compiled_path(key, type)
|
42
|
+
compiled_path(key, type).relative_path_from(public_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def destination_compiled_path(key, type)
|
46
|
+
"/#{relative_compiled_path(key, type)}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def public_path
|
50
|
+
@public_path ||= Rails.root.join('public')
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_reader :paths
|
56
|
+
|
57
|
+
def initialize(key, type, options = {})
|
58
|
+
@type = type
|
59
|
+
@key = key
|
60
|
+
@paths = JuicerRails.config[type.to_s][key.to_s]
|
61
|
+
@destination_dir = self.class.compiled_directory
|
62
|
+
@destination_path = self.class.compiled_path(key, type)
|
63
|
+
ensure_destination_directory_exists
|
64
|
+
end
|
65
|
+
|
66
|
+
# Produces production ready assets.
|
67
|
+
# Merges, appends timestamps for images, embeds images into stylesheets
|
68
|
+
# and tries to do everything what juicer can.
|
69
|
+
# TODO: only merging and cache buster are implemented at the moment
|
70
|
+
def compile
|
71
|
+
merge
|
72
|
+
bust_cache
|
73
|
+
end
|
74
|
+
|
75
|
+
# Depending on type merges and saves compiled asset
|
76
|
+
def merge
|
77
|
+
if @type == 'js'
|
78
|
+
merger = merge_javascripts
|
79
|
+
elsif @type == 'css'
|
80
|
+
merger = merge_stylesheets
|
81
|
+
end
|
82
|
+
save(merger)
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
def merge_javascripts
|
87
|
+
Juicer::Merger::JavaScriptMerger.new(@paths)
|
88
|
+
end
|
89
|
+
|
90
|
+
def merge_stylesheets
|
91
|
+
Juicer::Merger::StylesheetMerger.new(@paths, :document_root => Rails.root.join('public/stylesheets'))
|
92
|
+
end
|
93
|
+
|
94
|
+
def save(compiler)
|
95
|
+
compiler.save(@destination_path.to_s)
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def bust_cache
|
100
|
+
Juicer::CssCacheBuster.new.save(@destination_path.to_s)
|
101
|
+
self
|
102
|
+
end
|
103
|
+
|
104
|
+
def ensure_destination_directory_exists
|
105
|
+
unless @destination_dir.exist?
|
106
|
+
FileUtils.mkdir_p(@destination_dir.to_s)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'juicer-rails/collection'
|
2
|
+
|
3
|
+
module Juicer::Helper
|
4
|
+
|
5
|
+
def merged_javascripts(key)
|
6
|
+
javascript_include_tag(Juicer::Collection.dispatch(key, 'js'))
|
7
|
+
end
|
8
|
+
|
9
|
+
def merged_stylesheets(key)
|
10
|
+
stylesheet_link_tag(Juicer::Collection.dispatch(key, 'css'))
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
ActionView::Base.send(:include, Juicer::Helper)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module JuicerRails
|
4
|
+
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
|
7
|
+
initializer "juicer_rails.init" do
|
8
|
+
::JuicerRails.setup do |juicer|
|
9
|
+
juicer.config_file ||= Rails.root.join('config/assets.yml')
|
10
|
+
juicer.config ||= YAML.load_file(juicer.config_file)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: juicer-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Micha\xC5\x82 \xC5\x81omnicki"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-27 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: juicer
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
version: "1.0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: actionpack
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 2
|
42
|
+
- 1
|
43
|
+
version: "2.1"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Juicer-rails adds helpers for easy embedding juicer-packaged assets
|
47
|
+
email:
|
48
|
+
- michal.lomnicki@gmail.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- CHANGELOG.rdoc
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
- Rakefile
|
61
|
+
- init.rb
|
62
|
+
- juicer-rails.gemspec
|
63
|
+
- lib/juicer-rails.rb
|
64
|
+
- lib/juicer-rails/collection.rb
|
65
|
+
- lib/juicer-rails/helper.rb
|
66
|
+
- lib/juicer-rails/railtie.rb
|
67
|
+
- lib/juicer-rails/version.rb
|
68
|
+
- test/helper.rb
|
69
|
+
- test/test_juicer-rails.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: https://github.com/mlomnicki/juicer-rails
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project: juicer-rails
|
96
|
+
rubygems_version: 1.3.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Rails helpers for Juicer
|
100
|
+
test_files: []
|
101
|
+
|