Module: Middleman::GoogleAnalytics::Helpers

Defined in:
lib/middleman-google-analytics/helpers.rb

Instance Method Summary collapse

Instance Method Details

#google_analytics_tagObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/middleman-google-analytics/helpers.rb', line 9

def google_analytics_tag
  options = extensions[:google_analytics].options

  return nil if options.disable

  file = File.join(File.dirname(__FILE__), 'analytics.js.erb')
  context = { options: options }
  content = Erubis::FastEruby.new(File.read(file)).evaluate(context)
  content = Uglifier.compile(content) if options.minify

  if options.output.to_sym == :html
    content = indent(content) unless options.minify
    (:script, content, type: 'text/javascript')
  else
    content
  end
end

#indent(content) ⇒ Object

Ugly but true



28
29
30
31
32
# File 'lib/middleman-google-analytics/helpers.rb', line 28

def indent(content)
  str = "\n"
  content.each_line { |line| str << line.indent(2) }
  str
end