Skip to content

Commit

Permalink
Merge pull request #26 from janosrusiczki/permit-root-level-js-files
Browse files Browse the repository at this point in the history
Permit root level output of asset files
  • Loading branch information
janosrusiczki authored Dec 3, 2017
2 parents 9762fe4 + 3f0317d commit c33f56d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/japr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
require 'japr/converter'
require 'japr/compressor'
require 'japr/template'
require 'japr/templates/template_helper'
require 'japr/templates/javascript_tag_template'
require 'japr/templates/css_tag_template'
require 'japr/pipeline'
Expand Down
5 changes: 4 additions & 1 deletion lib/japr/templates/css_tag_template.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module JAPR
# Default output for CSS assets
class CssTagTemplate < JAPR::Template
include JAPR::TemplateHelper

def self.filetype
'.css'
end
Expand All @@ -10,7 +12,8 @@ def self.priority
end

def html
"<link href='/#{@path}/#{@filename}' rel='stylesheet' type='text/css' />"
"<link href='#{output_path}/#{@filename}' " \
"rel='stylesheet' type='text/css' />"
end
end
end
5 changes: 4 additions & 1 deletion lib/japr/templates/javascript_tag_template.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module JAPR
# Default output for JavaScript assets
class JavaScriptTagTemplate < JAPR::Template
include JAPR::TemplateHelper

def self.filetype
'.js'
end
Expand All @@ -10,7 +12,8 @@ def self.priority
end

def html
"<script src='/#{@path}/#{@filename}' type='text/javascript'></script>"
"<script src='#{output_path}/#{@filename}' " \
"type='text/javascript'></script>"
end
end
end
14 changes: 14 additions & 0 deletions lib/japr/templates/template_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module JAPR
module TemplateHelper
def output_path
root_path? ? '' : "/#{@path}"
end

def root_path?
stripped_path = @path.to_s.strip
stripped_path.nil? ||
stripped_path.empty? ||
stripped_path == '/'
end
end
end

0 comments on commit c33f56d

Please sign in to comment.