@@ -75,29 +75,48 @@ def build(logical_path, options = {})
75
75
end
76
76
77
77
def build_str ( source , logical_path , options = { } )
78
- filename = path_reader . expand ( logical_path ) . to_s
79
-
80
78
options = options . merge ( requirable : false )
81
- asset = build_asset ( source , logical_path , filename , requirable : false )
79
+ process_string ( source , logical_path , options )
82
80
83
81
preload . each { |path | process_require path , options }
84
82
85
- process_requires asset , filename , options
86
- @assets << asset
87
83
self
88
84
end
89
85
90
- def build_require ( logical_path , options = { } )
91
- process_require ( logical_path , options )
86
+ # Build the given asset as a ruby source, ignoring any actual file
87
+ # extension for asset.
88
+ #
89
+ # Handles a ruby file (on disk) as the entry point to the application.
90
+ # This method ensures the file is compiled as a ruby source, irrelevant
91
+ # of its actual file extension. This is useful in sprockets contexts
92
+ # where a ruby file may be handled after it has been through other
93
+ # engines, so its file extension might not identify it as a ruby
94
+ # source.
95
+ #
96
+ def build_require ( source , logical_path , options = { } )
97
+ process_string source , logical_path , options
98
+ end
99
+
100
+ # @private
101
+ #
102
+ # Process the given string as a ruby source, ignoring the path for
103
+ # processor type. Used to force a processor for the given path
104
+ # compilation.
105
+ def process_string ( source , logical_path , options )
106
+ filename = path_reader . expand ( logical_path ) . to_s
107
+ asset = build_asset ( source , logical_path , default_processor , options )
108
+
109
+ process_requires ( asset , filename , options )
110
+ @assets << asset
92
111
end
93
112
94
- def process_require ( logical_path , options )
113
+ def process_require ( logical_path , options , processor = nil )
95
114
return if prerequired . include? ( logical_path )
96
115
return if processed . include? ( logical_path )
97
116
processed << logical_path
98
117
99
118
filename = path_reader . expand ( logical_path ) . to_s
100
- asset = find_asset logical_path , options
119
+ asset = find_asset logical_path , options , processor
101
120
102
121
process_requires asset , filename , options
103
122
@assets << asset
@@ -109,7 +128,7 @@ def process_requires(asset, filename, options)
109
128
end
110
129
end
111
130
112
- def find_asset ( logical_path , options )
131
+ def find_asset ( logical_path , options , processor = nil )
113
132
cached_asset ( logical_path ) do
114
133
source = stub? ( logical_path ) ? '' : read ( logical_path )
115
134
@@ -121,15 +140,19 @@ def find_asset(logical_path, options)
121
140
end
122
141
end
123
142
124
- filename = path_reader . expand ( logical_path ) . to_s
143
+ filename = path_reader . expand ( logical_path ) . to_s
144
+ processor ||= processor_for ( filename )
125
145
126
- build_asset ( source , logical_path , filename , options . merge ( requirable : true ) )
146
+ build_asset ( source , logical_path , processor , options . merge ( requirable : true ) )
127
147
end
128
148
end
129
149
130
- def build_asset ( source , logical_path , filename , options )
131
- extname = File . extname ( filename )
132
- processor = processors . fetch ( extname ) { default_processor }
150
+ def processor_for ( filename )
151
+ extname = File . extname ( filename )
152
+ processors . fetch ( extname ) { default_processor }
153
+ end
154
+
155
+ def build_asset ( source , logical_path , processor , options )
133
156
options = compiler_options . merge ( options )
134
157
135
158
result = processor . new ( source , logical_path , options )
0 commit comments