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

Support turbolinks data attributes #36

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
7 changes: 6 additions & 1 deletion lib/jekyll/assets_plugin/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Configuration
:compress => { :css => nil, :js => nil },
:cachebust => :hard,
:cache_assets => false,
:gzip => %w{ text/css application/javascript }
:gzip => %w{ text/css application/javascript },
:turbolinks => false
}.freeze


Expand Down Expand Up @@ -51,6 +52,10 @@ def cache_assets?
!!@data.cache_assets
end

def turbolinks?
!!@data.turbolinks
end


def gzip
return @data.gzip if @data.gzip.is_a? Array
Expand Down
16 changes: 12 additions & 4 deletions lib/jekyll/assets_plugin/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Jekyll
module AssetsPlugin
class Renderer

STYLESHEET = '<link rel="stylesheet" type="text/css" href="%s">'
JAVASCRIPT = '<script type="text/javascript" src="%s"></script>'
STYLESHEET = '<link rel="stylesheet" type="text/css" href="%s" data-turbolinks-track>'
JAVASCRIPT = '<script type="text/javascript" src="%s" data-turbolinks-track></script>'


def initialize context, logical_path
Expand All @@ -25,14 +25,22 @@ def render_asset_path
def render_javascript
@path << ".js" if File.extname(@path).empty?

JAVASCRIPT % render_asset_path
ret = JAVASCRIPT % render_asset_path
if !@site.assets_config.turbolinks?
ret = ret.gsub(/data-turbolinks-track/, '')
end
ret
end


def render_stylesheet
@path << ".css" if File.extname(@path).empty?

STYLESHEET % render_asset_path
ret = STYLESHEET % render_asset_path
if !@site.assets_config.turbolinks?
ret = ret.gsub(/data-turbolinks-track/, '')
end
ret
end

end
Expand Down