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

asset helpers work again with new sprockets #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions lib/wisepdf/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ def configure
end

def use_asset_pipeline?
return true if ::Rails.configuration.assets.enabled.nil?
false
#return true if ::Rails.configuration.assets.enabled.nil?

!!(::Rails.configuration.assets.enabled)
#!!(::Rails.configuration.assets.enabled)
end

def reset!
Expand Down
11 changes: 7 additions & 4 deletions lib/wisepdf/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,31 @@ def wisepdf_javascript_tag(*sources)

module Assets
def wisepdf_stylesheet_tag(*sources)
env = ::Sprockets::Railtie.build_environment(::Rails.application)
sources.collect { |source|
filename = ( source =~ /.css\z/ ? source : source + '.css' )
"<style type='text/css'>
#{::Rails.application.assets.find_asset(filename)}
#{env.find_asset(filename)}
</style>"
}.join("\n").html_safe
end

def wisepdf_image_tag(img, options={})
env = ::Sprockets::Railtie.build_environment(::Rails.application)
if File.exists? img
image_tag "file://#{img}", options
elsif asset = ::Rails.application.assets.find_asset(img)
image_tag "file:///#{asset.pathname.to_s}", options
elsif asset = env.find_asset(img)
image_tag "file://#{asset.pathname.to_s}", options
end
end

def wisepdf_javascript_tag(*sources)
env = ::Sprockets::Railtie.build_environment(::Rails.application)
sources.collect { |source|
filename = ( source =~ /.js\z/ ? source : source + '.js' )
"<script type='text/javascript'>
//<![CDATA[
#{::Rails.application.assets.find_asset(filename)}
#{env.find_asset(filename)}
//]]>
</script>"
}.join("\n").html_safe
Expand Down
13 changes: 10 additions & 3 deletions lib/wisepdf/render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ module Wisepdf
module Render
def self.included(base)
base.class_eval do
alias_method_chain :render, :wisepdf
alias_method_chain :render_to_string, :wisepdf
after_filter :clean_temp_files
# alias_method_chain :render, :wisepdf
# alias_method_chain :render_to_string, :wisepdf

alias_method :render_without_wisepdf, :render
alias_method :render, :render_with_wisepdf

alias_method :render_to_string_without_wisepdf, :render_to_string
alias_method :render_to_string, :render_to_string_with_wisepdf

after_action :clean_temp_files
end
end

Expand Down