nanoc-toolbox 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nanoc-toolbox (0.0.8)
4
+ nanoc-toolbox (0.1.1)
5
5
  jsmin (~> 1.0)
6
6
  nanoc (~> 3.4)
7
7
  nokogiri (~> 1.4)
data/README.md CHANGED
@@ -21,6 +21,7 @@ If you feel something's missing, feel free to contribute.
21
21
  * **Blogging Extra**: Add extra blog post behavior
22
22
  * **Tagging Extra**: Add extra tagging behavior
23
23
  * **Disqus**: Disqus comments helper
24
+ * **Github Gist**: Github Gist helper
24
25
 
25
26
  ### Filters
26
27
 
@@ -5,6 +5,7 @@ require 'nanoc/toolbox/helpers/disqus'
5
5
  require 'nanoc/toolbox/helpers/blogging_extra'
6
6
  require 'nanoc/toolbox/helpers/tagging_extra'
7
7
  require 'nanoc/toolbox/helpers/google_analytics'
8
+ require 'nanoc/toolbox/helpers/github_gist'
8
9
 
9
10
  # This module will regroup all the helpers for nanoc
10
11
  module Nanoc::Toolbox::Helpers
@@ -0,0 +1,40 @@
1
+ module Nanoc::Toolbox::Helpers
2
+
3
+ # NANOC Helper for Github Gists
4
+ #
5
+ # This module contains helper functions to embed gists to your content
6
+ #
7
+ # @see https://gist.github.com/
8
+ #
9
+ # @author Anouar ADLANI <anouar@adlani.com>
10
+ module GithubGist
11
+ include Nanoc::Toolbox::Helpers::HtmlTag
12
+
13
+ # GIST script base URL
14
+ GIST_HOST = "https://gist.github.com"
15
+ GIST_EXT = "js"
16
+
17
+ # Generates the script tag for the supplied Gist ID
18
+ # optionaly displays only the specified file
19
+ #
20
+ # @example
21
+ # gist(1)
22
+ # #=> <script src="https://gist.github.com/1.js"> </script>
23
+ # gist(1, "gistfile1.txt")
24
+ # #=> <script src="https://gist.github.com/1.js?file=gistfile1.txt"></script>
25
+ #
26
+ # @param [Integer] gist_id - the ID of the Gist
27
+ # @param [String] filename - the optional filename to display
28
+ def gist(gist_id, filename=nil)
29
+ raise ArgumentError, "Gist ID should be a Integer" unless gist_id.is_a? Integer
30
+ url = "#{GIST_HOST}/#{gist_id}.#{GIST_EXT}"
31
+
32
+ if filename
33
+ raise ArgumentError, "Filename should be a string" unless filename.is_a? String
34
+ url += "?file=#{filename}"
35
+ end
36
+
37
+ content_tag :script, "", :src => url
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,3 @@
1
- require 'nanoc/toolbox/helpers/html_tag'
2
-
3
1
  module Nanoc::Toolbox::Helpers
4
2
 
5
3
  # NANOC Helper for the Gravatar avatars
@@ -4,7 +4,7 @@ module Nanoc
4
4
  module Version
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- PATCH = 0
7
+ PATCH = 1
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ class GithubGistDummyClass
4
+ include Nanoc::Toolbox::Helpers::GithubGist
5
+ end
6
+
7
+ describe Nanoc::Toolbox::Helpers::GithubGist do
8
+ subject { GithubGistDummyClass.new }
9
+ it {should respond_to(:gist) }
10
+
11
+ describe "#gist" do
12
+ context "without a filename" do
13
+ it "takes at list a Gist ID as parameter" do
14
+ lambda{ subject.gist }.should raise_error(ArgumentError)
15
+ end
16
+
17
+ it "ensures that Gist ID is an Integer" do
18
+ lambda{ subject.gist('abc') }.should raise_error(ArgumentError)
19
+ lambda{ subject.gist('123') }.should raise_error(ArgumentError)
20
+ lambda{ subject.gist(12345) }.should_not raise_error(ArgumentError)
21
+ end
22
+
23
+ it "returns the script tag for a gist" do
24
+ src = "https://gist.github.com/123.js"
25
+ subject.gist(123).should eq %Q{<script src="#{src}"></script>}
26
+ end
27
+ end
28
+
29
+ context "with a filename" do
30
+ it "ensures that the file name is an String" do
31
+ lambda{ subject.gist(12345, 12345) }.should raise_error(ArgumentError)
32
+ lambda{ subject.gist(12345, 'index.html') }.should_not raise_error(ArgumentError)
33
+ end
34
+
35
+ it "returns the script tag for a specific file if specified" do
36
+ src = "https://gist.github.com/123.js?file=README.md"
37
+ subject.gist(123, "README.md").should eq %Q{<script src="#{src}"></script>}
38
+ end
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-18 00:00:00.000000000 Z
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nanoc
@@ -134,6 +134,7 @@ files:
134
134
  - lib/nanoc/toolbox/helpers.rb
135
135
  - lib/nanoc/toolbox/helpers/blogging_extra.rb
136
136
  - lib/nanoc/toolbox/helpers/disqus.rb
137
+ - lib/nanoc/toolbox/helpers/github_gist.rb
137
138
  - lib/nanoc/toolbox/helpers/google_analytics.rb
138
139
  - lib/nanoc/toolbox/helpers/gravatar.rb
139
140
  - lib/nanoc/toolbox/helpers/html_tag.rb
@@ -147,6 +148,7 @@ files:
147
148
  - spec/filters/js_minify_spec.rb
148
149
  - spec/helpers/blogging_extra_spec.rb
149
150
  - spec/helpers/disqus_spec.rb
151
+ - spec/helpers/github_gist_spec.rb
150
152
  - spec/helpers/google_analytics_spec.rb
151
153
  - spec/helpers/gravatar_spec.rb
152
154
  - spec/helpers/html_tag_spec.rb