From 43223eeaa8c542e6ac9a8d0ddef7ca37ce56544a Mon Sep 17 00:00:00 2001 From: Sean Schofield Date: Thu, 2 Jun 2011 15:11:34 -0400 Subject: [PATCH 1/2] New --ga option for generating google analytics info in the layout --- lib/guides/cli.rb | 2 ++ lib/guides/generator.rb | 5 +++-- lib/guides/templates/source/layout.html.erb | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/guides/cli.rb b/lib/guides/cli.rb index 0a58d8b..3aeaa7c 100644 --- a/lib/guides/cli.rb +++ b/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 => :string, :banner => "google analytics id (ex. \"UA-12345-6\")" + def build if options[:clean] FileUtils.rm_rf(File.join(Guides.root, options[:production] ? 'output' : 'staging')) diff --git a/lib/guides/generator.rb b/lib/guides/generator.rb index 014eeaa..4a1821a 100644 --- a/lib/guides/generator.rb +++ b/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$/ diff --git a/lib/guides/templates/source/layout.html.erb b/lib/guides/templates/source/layout.html.erb index 826e8af..999045b 100644 --- a/lib/guides/templates/source/layout.html.erb +++ b/lib/guides/templates/source/layout.html.erb @@ -89,5 +89,20 @@ + <% if @ga %> + + <% end %> From 24b28e27b96fdd8a85a52b6f870d2dfc57aa15cb Mon Sep 17 00:00:00 2001 From: Sean Schofield Date: Wed, 3 Aug 2011 09:05:57 -0400 Subject: [PATCH 2/2] New approach relies on a hard-coded string --- lib/guides/cli.rb | 2 +- lib/guides/templates/source/layout.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/guides/cli.rb b/lib/guides/cli.rb index 3aeaa7c..483fc2b 100644 --- a/lib/guides/cli.rb +++ b/lib/guides/cli.rb @@ -23,7 +23,7 @@ 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 => :string, :banner => "google analytics id (ex. \"UA-12345-6\")" + method_option "ga", :type => :boolean, :default => false def build if options[:clean] diff --git a/lib/guides/templates/source/layout.html.erb b/lib/guides/templates/source/layout.html.erb index 999045b..320b0a2 100644 --- a/lib/guides/templates/source/layout.html.erb +++ b/lib/guides/templates/source/layout.html.erb @@ -93,7 +93,7 @@