Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Strockets API and cleaner inner working
- Loading branch information
Showing
10 changed files
with
147 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
require "strockets/version" | ||
require "strockets/config" | ||
require "strockets/processor" | ||
require "strockets/bundle" | ||
require "strockets/environment" | ||
require "strockets/stitch_postprocessor" | ||
require "strockets/railtie" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'strockets/railties/engine' if defined? Rails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Strockets | ||
module Railties | ||
class Engine < ::Rails::Engine | ||
initializer 'strockets.configure_rails_initialization' do |app| | ||
app.assets.append_path Strockets.stitch_path | ||
|
||
app.assets.register_postprocessor( | ||
'application/javascript', | ||
Strockets::StitchPostprocessor | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Strockets | ||
class StitchPostprocessor < Tilt::Template | ||
HEADER_PATTERN = Sprockets::DirectiveProcessor::HEADER_PATTERN | ||
DIRECTIVE_PATTERN = Sprockets::DirectiveProcessor::DIRECTIVE_PATTERN | ||
|
||
def prepare; end | ||
|
||
def evaluate(context, locals, &block) | ||
@context = context | ||
|
||
stitch? ? define : data | ||
end | ||
|
||
protected | ||
attr_reader :context | ||
|
||
def process_requires | ||
|
||
end | ||
|
||
def stitch? | ||
stitch = directive? | ||
|
||
if stitch.nil? | ||
stitch = Strockets.default_to_stitch? | ||
stitch = !stitch if exception? | ||
end | ||
|
||
stitch | ||
end | ||
|
||
def define | ||
context.require_asset "stitch" | ||
|
||
"\n#{ Strockets.namespace }.define({'#{ | ||
context.logical_path | ||
}': function(exports, require, module) {\n#{ | ||
indent(data) | ||
}\n}});\n" | ||
end | ||
|
||
def exception? | ||
Strockets.stitch_exceptions.any?{ |e| e.match(context.pathname.to_s) } | ||
end | ||
|
||
def directive? | ||
header = context.pathname.read[HEADER_PATTERN, 0] || "" | ||
header.lines.each do |line| | ||
if directive = line[DIRECTIVE_PATTERN, 1] | ||
name, *args = Shellwords.shellwords(directive) | ||
if name == "stitch" | ||
case args.first | ||
when "true" then return true | ||
when "false" then return false | ||
end | ||
end | ||
end | ||
end | ||
|
||
nil | ||
end | ||
|
||
def indent(string) | ||
string.gsub(/$(.)/m, "\\1 ").strip | ||
end | ||
end | ||
end | ||
|
||
class Sprockets::DirectiveProcessor | ||
# This is just a placeholder to make Sprockets erase stitch directives | ||
def process_stitch_directive(arg) | ||
end | ||
end |