Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
wants to merge 2 commits into from

2 participants

@schof

I didn't bother with a spec since there are already 8 failing specs. I did test it manually though.

@wagenet
Collaborator

All the specs do pass. You should just have to bundle install and bundle exec rspec spec. So tests would still be appreciated.

@schof
@wagenet
Collaborator

Were you able to get tests running? If so, can you write some for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 2, 2011
  1. @schof
Commits on Aug 3, 2011
  1. @schof
This page is out of date. Refresh to see the latest.
View
2  lib/guides/cli.rb
@@ -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'))
View
5 lib/guides/generator.rb
@@ -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('|')})$/
@@ -78,6 +78,7 @@ def initialize(options)
@warnings = options[:warnings]
@all = options[:all]
@production = options[:production]
+ @ga = options[:ga]
@meta = Guides.meta
end
@@ -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$/
View
15 lib/guides/templates/source/layout.html.erb
@@ -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>
Something went wrong with that request. Please try again.