Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 12 commits
  • 12 files changed
  • 0 comments
  • 3 contributors
2  .travis.yml
@@ -4,4 +4,4 @@ language: ruby
4 4
 rvm:
5 5
   - 1.9.2
6 6
   - 1.9.3
7  
-  - jruby-19mode
  7
+  - jruby-18mode
15  Rakefile
... ...
@@ -1,10 +1,10 @@
1 1
 require 'rubygems'
2 2
 require 'bundler/setup'
3 3
 require 'rspec/core/rake_task'
4  
-require 'rake'
  4
+require 'awestruct/version'
  5
+
  6
+task :default => :build
5 7
 
6  
-task :default => :test
7  
-task :test => :spec
8 8
 if !defined?(RSpec)
9 9
   puts "spec targets require RSpec"
10 10
 else
@@ -15,3 +15,12 @@ else
15 15
   end
16 16
 end
17 17
 
  18
+desc "Run all tests and build the gem"
  19
+task :build => :spec do
  20
+  system "gem build awestruct.gemspec"
  21
+end
  22
+ 
  23
+desc "Release the gem to rubygems"
  24
+task :release => :build do
  25
+  system "gem push awestruct-#{Awestruct::VERSION}.gem"
  26
+end
8  awestruct.gemspec
... ...
@@ -1,6 +1,6 @@
1 1
 require File.expand_path("../lib/awestruct/version", __FILE__)
2 2
 
3  
-Gem::Specification.new do |s|
  3
+spec = Gem::Specification.new do |s|
4 4
     s.platform       =   Gem::Platform::RUBY
5 5
     s.name           =   "awestruct"
6 6
     s.version        =   Awestruct::VERSION
@@ -30,8 +30,12 @@ Gem::Specification.new do |s|
30 30
     s.add_dependency 'compass-960-plugin', '~> 0.10.4'
31 31
     s.add_dependency 'bootstrap-sass', '~> 2.0.1'
32 32
     s.add_dependency 'org-ruby', '~> 0.5.3'
33  
-    s.add_dependency 'fssm', '~> 0.2.8.1'
  33
+    s.add_dependency 'fssm', '~> 0.2.8'
34 34
     s.add_dependency 'json', '~> 1.6.6'
35 35
     s.add_dependency 'notifier', '~> 0.1.4'
  36
+    s.add_dependency 'git', '~> 1.2.5'
  37
+
  38
+    s.add_development_dependency 'rspec', '~> 2.9'
  39
+    s.add_development_dependency 'rake', '~> 0.9.2'
36 40
 end
37 41
 
8  bin/awestruct
@@ -9,6 +9,7 @@ require 'awestruct/commands/init'
9 9
 require 'awestruct/commands/generate'
10 10
 require 'awestruct/commands/server'
11 11
 require 'awestruct/commands/deploy'
  12
+require 'awestruct/commands/git_hub_pages'
12 13
 require 'yaml'
13 14
 require 'fssm'
14 15
 require 'fileutils'
@@ -203,7 +204,12 @@ if ( options.deploy )
203 204
   end
204 205
 
205 206
   puts "deploying to '#{options.profile}'"
206  
-  cmd = Awestruct::Commands::Deploy.new( site_path, deploy_data )
  207
+  if (deploy_data['host'] == 'github_pages')
  208
+    puts "publishing to github pages"
  209
+    cmd = Awestruct::Commands::GitHubPages.new( site_path )
  210
+  else
  211
+    cmd = Awestruct::Commands::Deploy.new( site_path, deploy_data )
  212
+  end
207 213
   cmd.run
208 214
   puts "deploy finished"
209 215
   exit
8  lib/awestruct/commands/frameworks/bootstrap/base_layout.html.haml
@@ -8,17 +8,17 @@
8 8
       body {
9 9
         padding-top: 60px;
10 10
       }
11  
-    %link{ :rel=>'stylesheet', :type=>'text/css', :href=>'/stylesheets/styles.css' }
  11
+    %link{ :rel=>'stylesheet', :type=>'text/css', :href=>"#{site.base_url}/stylesheets/styles.css" }
12 12
     /[if lt IE 9]
13 13
       %script{ :type=>'text/javascript', :src=>'//html5shim.googlecode.com/svn/trunk/html5.js' }
14 14
   %body
15 15
     .navbar.navbar-fixed-top
16 16
       .navbar-inner
17 17
         .container
18  
-          %a.brand{ :href=>'/' } Project Name
  18
+          %a.brand{ :href=>"#{site.base_url}" } Project Name
19 19
           %ul.nav
20 20
             %li
21  
-              %a{ :href=>'/' } Home
  21
+              %a{ :href=>"#{site.base_url}" } Home
22 22
     .container
23 23
       ~ content
24 24
       %hr
@@ -26,4 +26,4 @@
26 26
         %p © Organization #{Date.today.year}
27 27
     -# Uncomment script tags (remove leading -#) when you're ready to use behaviors
28 28
     -# %script{ :type=>'text/javascript', :src=>'//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.1/jquery.min.js' }
29  
-    -# %script{ :type=>'text/javascript', :src=>'/javascripts/bootstrap-collapse.js' }
  29
+    -# %script{ :type=>'text/javascript', :src=>"#{site.base_url}/javascripts/bootstrap-collapse.js" }
55  lib/awestruct/commands/git_hub_pages.rb
... ...
@@ -0,0 +1,55 @@
  1
+require 'git'
  2
+
  3
+module Awestruct
  4
+  module Commands
  5
+
  6
+    class GitHubPages
  7
+      def initialize( site_path )
  8
+        @site_path = site_path
  9
+        @git       = Git.open(".")
  10
+      end
  11
+
  12
+      def run
  13
+        @git.status.changed.empty? ? publish_site : message_for(:existing_changes)
  14
+      end
  15
+
  16
+      private
  17
+      def publish_site
  18
+        current_branch = @git.branch
  19
+        checkout_pages_branch
  20
+        add_and_commit_site @site_path
  21
+        push_and_restore current_branch
  22
+      end
  23
+
  24
+      def checkout_pages_branch
  25
+        @git.branch('gh-pages').checkout
  26
+      end
  27
+
  28
+      def add_and_commit_site( path )
  29
+        @git.with_working( path ) do
  30
+          @git.add(".")
  31
+          begin
  32
+            @git.commit("Published to gh-pages.")
  33
+          rescue Git::GitExecuteError => e
  34
+            $stderr.puts "Can't commit. #{e}."
  35
+          end
  36
+        end
  37
+      end
  38
+
  39
+      def push_and_restore( branch )
  40
+        @git.reset_hard
  41
+        @git.push( 'origin', 'gh-pages' )
  42
+        @git.checkout( branch )
  43
+      end
  44
+
  45
+      def message_for( key )
  46
+        $stderr.puts case key
  47
+        when :existing_changes 
  48
+          "You have uncommitted changes in the working branch. Please commit or stash them."
  49
+        else 
  50
+          "An error occured."
  51
+        end
  52
+      end
  53
+    end
  54
+  end
  55
+end
97  lib/awestruct/extensions/extend_string.rb
... ...
@@ -0,0 +1,97 @@
  1
+# RemoveAccents version 1.0.3 (c) 2008-2009 Solutions Informatiques Techniconseils inc.
  2
+# 
  3
+# This module adds 2 methods to the string class. 
  4
+# Up-to-date version and documentation available at:
  5
+#
  6
+# http://www.techniconseils.ca/en/scripts-remove-accents-ruby.php
  7
+#
  8
+# This script is available under the following license :
  9
+# Creative Commons Attribution-Share Alike 2.5.
  10
+#
  11
+# See full license and details at :
  12
+# http://creativecommons.org/licenses/by-sa/2.5/ca/
  13
+#
  14
+# Version history:
  15
+#   * 1.0.3 : July 23 2009
  16
+#               Corrected some incorrect character codes. Source is now wikipedia at:
  17
+#                 http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Related_character_maps
  18
+#               Thanks to Raimon Fernandez for pointing out the incorrect codes.
  19
+#   * 1.0.2 : October 29 2008
  20
+#               Slightly optimized version of urlize - Jonathan Grenier (jgrenier@techniconseils.ca)
  21
+#   * 1.0.1 : October 29 2008
  22
+#               First public revision - Jonathan Grenier (jgrenier@techniconseils.ca)
  23
+#
  24
+
  25
+class String
  26
+  # The extended characters map used by removeaccents. The accented characters 
  27
+  # are coded here using their numerical equivalent to sidestep encoding issues.
  28
+  # These correspond to ISO-8859-1 encoding.
  29
+  ACCENTS_MAPPING = {
  30
+    'E' => [200,201,202,203],
  31
+    'e' => [232,233,234,235],
  32
+    'A' => [192,193,194,195,196,197],
  33
+    'a' => [224,225,226,227,228,229,230],
  34
+    'C' => [199],
  35
+    'c' => [231],
  36
+    'O' => [210,211,212,213,214,216],
  37
+    'o' => [242,243,244,245,246,248],
  38
+    'I' => [204,205,206,207],
  39
+    'i' => [236,237,238,239],
  40
+    'U' => [217,218,219,220],
  41
+    'u' => [249,250,251,252],
  42
+    'N' => [209],
  43
+    'n' => [241],
  44
+    'Y' => [221],
  45
+    'y' => [253,255],
  46
+    'AE' => [306],
  47
+    'ae' => [346],
  48
+    'OE' => [188],
  49
+    'oe' => [189]
  50
+  }
  51
+  
  52
+  
  53
+  # Remove the accents from the string. Uses String::ACCENTS_MAPPING as the source map.
  54
+  def removeaccents    
  55
+    str = String.new(self)
  56
+    String::ACCENTS_MAPPING.each {|letter,accents|
  57
+      packed = accents.pack('U*')
  58
+      rxp = Regexp.new("[#{packed}]", nil, 'U')
  59
+      str.gsub!(rxp, letter)
  60
+    }
  61
+    
  62
+    str
  63
+  end
  64
+  
  65
+  
  66
+  # Convert a string to a format suitable for a URL without ever using escaped characters.
  67
+  # It calls strip, removeaccents, downcase (optional) then removes the spaces (optional)
  68
+  # and finally removes any characters matching the default regexp (/[^-_A-Za-z0-9]/).
  69
+  #
  70
+  # Options
  71
+  #
  72
+  # * :downcase => call downcase on the string (defaults to true)
  73
+  # * :convert_spaces => Convert space to underscore (defaults to false)
  74
+  # * :regexp => The regexp matching characters that will be converting to an empty string (defaults to /[^-_A-Za-z0-9]/)
  75
+  def urlize(options = {})
  76
+    options[:downcase] ||= true
  77
+    options[:convert_spaces] ||= false
  78
+    options[:regexp] ||= /[^-_A-Za-z0-9]/
  79
+    
  80
+    str = self.strip.removeaccents
  81
+    str.downcase! if options[:downcase]
  82
+    str.gsub!(/\ /,'-') if options[:convert_spaces]
  83
+    str.gsub(options[:regexp], '')
  84
+  end
  85
+
  86
+  # This follows the generated ID rules
  87
+  def anchorize(options = {})
  88
+    options[:downcase] ||= true
  89
+    options[:convert_spaces] ||= false
  90
+    options[:regexp] ||= /[^-_A-Za-z0-9]/
  91
+    
  92
+    str = self.strip.removeaccents
  93
+    str.downcase! if options[:downcase]
  94
+    str.gsub!(/\ /,'_') if options[:convert_spaces]
  95
+    str.gsub(options[:regexp], '')
  96
+  end
  97
+end
21  lib/awestruct/extensions/tagger.rb
... ...
@@ -1,3 +1,5 @@
  1
+require 'awestruct/extensions/extend_string'
  2
+
1 3
 module Awestruct
2 4
   module Extensions
3 5
     class Tagger
@@ -24,11 +26,12 @@ def tag_links(delimiter = ', ', style_class = nil)
24 26
         end
25 27
       end
26 28
 
27  
-      def initialize(tagged_items_property, input_path, output_path='tags', pagination_opts={})
  29
+      def initialize(tagged_items_property, input_path, output_path='tags', opts={})
28 30
         @tagged_items_property = tagged_items_property
29 31
         @input_path  = input_path
30 32
         @output_path = output_path
31  
-        @pagination_opts = pagination_opts
  33
+        @sanitize = opts[:sanitize] || false
  34
+        @pagination_opts = opts
32 35
       end
33 36
 
34 37
       def execute(site)
@@ -81,7 +84,11 @@ def execute(site)
81 84
         end
82 85
 
83 86
         @tags.values.each do |tag|
84  
-          paginator = Awestruct::Extensions::Paginator.new( @tagged_items_property, @input_path, { :remove_input=>false, :output_prefix=>File.join( @output_path, tag.to_s), :collection=>tag.pages }.merge( @pagination_opts ) )
  87
+          ## Optionally sanitize tag URL
  88
+          output_prefix = File.join( @output_path, sanitize(tag.to_s) )
  89
+          options = { :remove_input=>false, :output_prefix=>output_prefix, :collection=>tag.pages }.merge( @pagination_opts )
  90
+          
  91
+          paginator = Awestruct::Extensions::Paginator.new( @tagged_items_property, @input_path, options )
85 92
           primary_page = paginator.execute( site )
86 93
           tag.primary_page = primary_page
87 94
         end
@@ -89,6 +96,14 @@ def execute(site)
89 96
         site.send( "#{@tagged_items_property}_tags=", ordered_tags )
90 97
       end
91 98
 
  99
+      def sanitize(string)
  100
+        #replace accents with unaccented version, go lowercase and replace and space with dash
  101
+        if @sanitize
  102
+          string.to_s.urlize({:convert_spaces=>true})
  103
+        else
  104
+          string
  105
+        end
  106
+      end
92 107
     end
93 108
   end
94 109
 end
2  lib/awestruct/version.rb
... ...
@@ -1,4 +1,4 @@
1 1
 
2 2
 module Awestruct
3  
-  VERSION='0.2.15'
  3
+  VERSION='0.2.18'
4 4
 end
17  spec/extensions/tagger_spec.rb
... ...
@@ -0,0 +1,17 @@
  1
+require 'spec_helper'
  2
+require 'awestruct/extensions/tagger'
  3
+
  4
+describe Awestruct::Extensions::Tagger do
  5
+
  6
+  before :each do
  7
+  end
  8
+
  9
+  it "should work" do
  10
+    Awestruct::Extensions::Tagger.new( :podcasts, 
  11
+                                       '/podcasts/index', 
  12
+                                       '/podcasts/tags', 
  13
+                                       :per_page=>5 )
  14
+  end
  15
+
  16
+end
  17
+
38  spec/git_hub_pages_spec.rb
... ...
@@ -0,0 +1,38 @@
  1
+require 'spec_helper'
  2
+require 'awestruct/commands/git_hub_pages'
  3
+
  4
+describe Awestruct::Commands::GitHubPages do
  5
+
  6
+  before :each do
  7
+    @site_path = "_site"
  8
+    @git = double("git")
  9
+    @git.stub_chain(:status, :changed, :empty?) { true }
  10
+    @git.stub(:branch).and_return 'master'
  11
+    Git.stub(:open).with(".").and_return( @git )
  12
+    @github = Awestruct::Commands::GitHubPages.new( @site_path )
  13
+    @github.stub(:checkout_pages_branch)
  14
+    @github.stub(:add_and_commit_site)
  15
+    @github.stub(:push_and_restore)
  16
+  end
  17
+
  18
+  it "should check for uncommitted changes" do
  19
+    @git.should_receive(:status) 
  20
+    @github.run
  21
+  end
  22
+
  23
+  it "should checkout the gh-pages branch" do
  24
+    @github.should_receive(:checkout_pages_branch)
  25
+    @github.run
  26
+  end
  27
+
  28
+  it "should use the site_path as the working directory" do
  29
+    @github.should_receive(:add_and_commit_site).with(@site_path)
  30
+    @github.run
  31
+  end
  32
+
  33
+  it "should push the updates and restore the current branch" do
  34
+    @github.should_receive(:push_and_restore).with('master')
  35
+    @github.run
  36
+  end
  37
+
  38
+end
5  spec/spec_helper.rb
... ...
@@ -0,0 +1,5 @@
  1
+
  2
+RSpec.configure do |conf|
  3
+  # Nothing at the moment
  4
+end
  5
+

No commit comments for this range

Something went wrong with that request. Please try again.