Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get rid of Jammit dependency in production mode #262

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ gem 'thin', '>=1.2.11'
gem 'tire' , '>= 0.3.0', '< 0.4'
gem 'json'
gem 'rest-client', :require => 'rest_client'
gem 'jammit'
gem 'pg'
# gem 'bson_ext', '>= 1.0.4'
gem 'rails_warden'
Expand Down Expand Up @@ -56,6 +55,8 @@ gem 'acts_as_reportable', '>=1.1.1'
# end

group :test, :development do
gem 'jammit'

# To use debugger
gem 'ruby-debug'
gem 'ZenTest', '>= 4.4.0'
Expand Down
38 changes: 38 additions & 0 deletions src/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,43 @@ def a_link(name, href, html_options)
return link.respond_to?(:html_safe) ? link.html_safe : link
end

unless defined? Jammit
# We don't need Jammit and all it's dependencies in the production mode.
# This should be all what's needed when running in production.

def include_stylesheets(*packages)
options = packages.extract_options!
if options[:embed_assets] == false
html = stylesheet_links(packages.map { |p| asset_url(p, :css) }, options)
else
datauri_tags = stylesheet_links(packages.map { |p| asset_url(p, :css, :datauri) }, options)
ie_tags = stylesheet_links(packages.map { |p| asset_url(p, :css) }, options)
html = ["<!--[if (!IE)|(gte IE 8)]><!-->",
datauri_tags,
"<!--<![endif]-->",
ie_tags,
"<!--[if lte IE 7]>",
"<![endif]-->"].join("\n")
end
html.html_safe
end

def include_javascripts(*packages)
options = packages.extract_options!
javascript_links(packages.map { |p| asset_url(p, :js) }, options).html_safe
end

def stylesheet_links(files, options)
files.map { |f| stylesheet_link_tag(f, options) }.join("\n")
end

def javascript_links(files, options)
files.map { |f| javascript_include_tag(f, options) }.join("\n")
end

def asset_url(package, extension, suffix = nil)
filename = "#{[package, suffix].compact.join("-")}.#{extension}"
"/assets/#{filename}"
end
end
end