Class: ShopifyCLI::Theme::DevServer::HotReload::ScriptInjector
- Inherits:
-
Object
- Object
- ShopifyCLI::Theme::DevServer::HotReload::ScriptInjector
- Defined in:
- lib/shopify_cli/theme/dev_server/hot_reload/script_injector.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(ctx, theme: nil) ⇒ ScriptInjector
constructor
A new instance of ScriptInjector.
- #inject(body:, dir:, mode:) ⇒ Object
Constructor Details
#initialize(ctx, theme: nil) ⇒ ScriptInjector
Returns a new instance of ScriptInjector.
9 10 11 12 13 |
# File 'lib/shopify_cli/theme/dev_server/hot_reload/script_injector.rb', line 9 def initialize(ctx, theme: nil) @ctx = ctx @theme = theme @sections_index = HotReload::SectionsIndex.new(theme) unless theme.nil? end |
Instance Method Details
#inject(body:, dir:, mode:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shopify_cli/theme/dev_server/hot_reload/script_injector.rb', line 15 def inject(body:, dir:, mode:) @mode = mode @dir = dir hot_reload_script = [ read("hot-reload-no-script.html"), "<script>", "(() => {", javascript_inline, *javascript_files.map { |file| read(file) }, "})();", "</script>", ].join("\n") body = body.join.sub("</body>", "#{hot_reload_script}\n</body>") [body] end |