Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New --ga option for generating google analytics info in the layout #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/guides/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def new(name)
method_option "clean", :type => :boolean
method_option "edge", :type => :boolean, :default => false
method_option "production", :type => :boolean, :default => true, :banner => "use production mode", :aliases => "-p"
method_option "ga", :type => :boolean, :default => false

def build
if options[:clean]
FileUtils.rm_rf(File.join(Guides.root, options[:production] ? 'output' : 'staging'))
Expand Down
5 changes: 3 additions & 2 deletions lib/guides/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

module Guides
class Generator
attr_reader :guides_dir, :source_dir, :output_dir, :edge, :warnings, :all
attr_reader :guides_dir, :source_dir, :output_dir, :edge, :ga, :warnings, :all

EXTENSIONS = %w(textile md html.erb)
GUIDES_RE = /\.(?:#{EXTENSIONS.map{|e| Regexp.escape(e)}.join('|')})$/
Expand All @@ -78,6 +78,7 @@ def initialize(options)
@warnings = options[:warnings]
@all = options[:all]
@production = options[:production]
@ga = options[:ga]

@meta = Guides.meta
end
Expand Down Expand Up @@ -139,7 +140,7 @@ def generate_guide(guide, output_file)

puts "Generating #{output_file}"
File.open(File.join(output_dir, output_file), 'w') do |f|
view = ActionView::Base.new(source_dir, :edge => edge, :production => @production)
view = ActionView::Base.new(source_dir, :edge => edge, :ga => ga, :production => @production)
view.extend(Helpers)

if guide =~ /\.html\.erb$/
Expand Down
15 changes: 15 additions & 0 deletions lib/guides/templates/source/layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,20 @@
<script type="text/javascript">
SyntaxHighlighter.all()
</script>
<% if @ga %>
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'GA TRACKING ID GOES HERE']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
<% end %>
</body>
</html>