Class: Antoinette::ClearScriptTag

Inherits:
Object
  • Object
show all
Defined in:
lib/antoinette/services/clear_script_tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(views_path: Rails.root.join("app", "views")) ⇒ ClearScriptTag

Returns a new instance of ClearScriptTag.



5
6
7
# File 'lib/antoinette/services/clear_script_tag.rb', line 5

def initialize(views_path: Rails.root.join("app", "views"))
  @views_path = views_path
end

Instance Method Details

#clear(template_path:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/antoinette/services/clear_script_tag.rb', line 9

def clear(template_path:)
  full_path = resolve_template_path(template_path)
  content = File.read(full_path)

  return unless content.match?(InjectScriptTag::MARKER)

  updated_content = content.gsub(/^.*#{InjectScriptTag::MARKER}.*\n?/o, "")

  File.write(full_path, updated_content)
end