Class: EasyHtmlGenerator::Generator::Service::Analytics
- Defined in:
- lib/easy_html_generator/generator/service/analytics.rb
Overview
this generator adds web tracking snippets to files in the dist folder
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#dest_path, #do_file, #do_input, #initialize, #input_to_output_file, #log, #log_running, #resolve_path_prefix, #should_do_file?, #src_path, #walk_files
Constructor Details
This class inherits a constructor from EasyHtmlGenerator::Generator::Base
Instance Method Details
#do_google(file) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/easy_html_generator/generator/service/analytics.rb', line 20 def do_google(file) return unless @config.google.enabled content = File.read(file) return if file.include? '<!-- Google Analytics -->' code = @config.google.code.sub('{GOOGLE_UA_ID}', @config.google.id) code = "<!-- Google Analytics -->#{code}<!-- End Google Analytics -->" content = content.sub('</head>', "#{code}</head>") File.write(file, content) end |
#generate ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/easy_html_generator/generator/service/analytics.rb', line 8 def generate return unless @config.enabled log_running selector = File.join(@project.dist_path_to(:views), @config.append_to_files) Dir[selector].each do |file| do_google file end end |