nanoc-fuel 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ .rvmrc
3
+ *.gem
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nanoc_deploy.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nanoc-fuel (0.0.5)
5
+ haml (>= 3.1.1)
6
+ nanoc (>= 3.1.6)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ cri (1.0.1)
12
+ haml (3.1.1)
13
+ nanoc (3.1.7)
14
+ nanoc3 (>= 3.1.7)
15
+ nanoc3 (3.1.7)
16
+ cri (>= 1.0.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ nanoc-fuel!
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010-2011 Jack Chu, Bob Whitney and contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ Nanoc Fuel
2
+ =============================
3
+
4
+ Nanoc Fuel is a nanoc gem that adds a bunch of useful helpers.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ - You need Nanoc 3.1.6 or above
10
+ - This gem requires haml 3.1.1 or above
11
+
12
+ If you're using bundler, just add this to your Gemfile:
13
+
14
+ gem 'nanoc-fuel'
15
+
16
+ Otherwise, you can just install the gem manually:
17
+
18
+ gem install nanoc-fuel
19
+
20
+ and then in your nanoc project, put this in lib/default.rb:
21
+
22
+ require 'nanoc-fuel/tasks'
23
+
24
+ Usage
25
+ ------------
26
+
27
+ For the Facebook/Google helpers:
28
+
29
+ In your nanoc project's lib/helpers.rb file, include one of the helpers:
30
+
31
+ include NanocFuel::Helpers::Facebook
32
+ include NanocFuel::Helpers::Google
33
+
34
+ Then, in your layout add any of these:
35
+
36
+ fb_init("FB APP ID HERE")
37
+
38
+ fb_comments("url", "num_posts", "width")
39
+
40
+ fb_like_btn("standard", "450", "true", "true")
41
+
42
+ ga_tracking("UA-XXXXX")
43
+
44
+ Contact
45
+ ------------
46
+ You can reach me at <jack@jackchu.com>.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rake/testtask'
7
+
8
+ task :default => :test
9
+
10
+ desc "Run tests"
11
+ task :test do
12
+ Rake::TestTask.new do |t|
13
+ t.libs << 'lib' << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ module NanocFuel
2
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ module NanocFuel
4
+ module Filters
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'haml'
4
+
5
+ module NanocFuel::Helpers
6
+ module Facebook
7
+ def fb_init(app_id)
8
+ template = File.read(File.expand_path("../templates/facebook/fb_init.haml", __FILE__))
9
+ Haml::Engine.new(template).render(Object.new, :app_id => app_id)
10
+ end
11
+
12
+ def fb_comments(url, num_posts, width)
13
+ template = File.read(File.expand_path("../templates/facebook/fb_comments.haml", __FILE__))
14
+ Haml::Engine.new(template).render(Object.new, :url => url, :num_posts => num_posts, :width => width)
15
+ end
16
+
17
+ def fb_like_btn(layout, width, show_faces, send)
18
+ template = File.read(File.expand_path("../templates/facebook/fb_like_btn.haml", __FILE__))
19
+ Haml::Engine.new(template).render(Object.new, :layout => layout, :width => width, :show_faces => show_faces, :send => send)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'haml'
4
+
5
+ module NanocFuel::Helpers
6
+ module Google
7
+ def ga_tracking(ua_id)
8
+ template = File.read(File.expand_path("../templates/google/ga_tracking_code.haml", __FILE__))
9
+ Haml::Engine.new(template).render(Object.new, :ua_id => ua_id)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ #!/usr/bin/env ruby
@@ -0,0 +1,35 @@
1
+ module NanocFuel
2
+ module Helpers
3
+
4
+ # @author Arnau Siches
5
+ #
6
+ # @version 0.1.0
7
+ #
8
+ # Provides some helper functions to process Rules.
9
+ module RuleTemplates
10
+
11
+ # Compiles the content as a set of Nanoc rules. Tries to use the
12
+ # +rules_dir+ attribute from the Config.yaml.
13
+ # If +rules_dir+ is not defined, it uses +"."+ as a base path.
14
+ #
15
+ # @example Config.yaml excerpt
16
+ #
17
+ # rules_dir: ['lib/rules/**', 'lib/other_rules']
18
+ #
19
+ # @example Rules excerpt
20
+ #
21
+ # # Finds any foo.rule in all directories defined in the Config.yaml
22
+ # load_rules('foo.rule')
23
+ #
24
+ # @param [String] filepath The file path to load.
25
+ #
26
+ # @return [Proc]
27
+ def load_templates(templates)
28
+ rule_template_path = 'rule_templates'
29
+ templates.each do |template|
30
+ instance_eval(File.read(File.expand_path("../#{rule_template_path}/#{template}", __FILE__)), template)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ %fb:comments{:href =>"#{url}", :num_posts=>"#{num_posts}", :width=>"#{width}"}
@@ -0,0 +1,19 @@
1
+ #fb-root
2
+ :javascript
3
+ window.fbAsyncInit = function() {
4
+ FB.init({appId: '#{app_id}', status: true, cookie: true, xfbml: true});
5
+ fbInitHook();
6
+ FB.Canvas.setSize();
7
+ };
8
+
9
+ function fbInitHook() {}
10
+
11
+ function sizeChangeCallback() {
12
+ FB.Canvas.setSize();
13
+ }
14
+
15
+ (function() {
16
+ var e = document.createElement('script'); e.async = true;
17
+ e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
18
+ document.getElementById('fb-root').appendChild(e);
19
+ }());
@@ -0,0 +1 @@
1
+ %iframe{:src=>"//www.facebook.com/plugins/like.php?href&amp;send=#{send}&amp;layout=#{layout}&amp;width=#{width}&amp;show_faces=#{show_faces}&amp;action=like&amp;colorscheme=light&amp;font&amp;height=80", :scrolling=>"no", :frameborder=>"0", :style=>"border:none; overflow:hidden; width:450px; height:80px;", :allowTransparency=>"true"}
@@ -0,0 +1,10 @@
1
+ :javascript
2
+ var _gaq = _gaq || [];
3
+ _gaq.push(['_setAccount', '#{ua_id}']);
4
+ _gaq.push(['_trackPageview']);
5
+
6
+ (function() {
7
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
8
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
9
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
10
+ })();
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module NanocFuel
4
+ module Helpers
5
+ autoload "Facebook", "nanoc-fuel/helpers/facebook"
6
+ autoload "Google", "nanoc-fuel/helpers/google"
7
+ autoload "RuleTemplates", "nanoc-fuel/helpers/rule_templates"
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ require 'nanoc-fuel'
4
+ require 'rake'
5
+
6
+ module NanocFuel::Tasks
7
+ end
8
+
9
+ Dir[File.dirname(__FILE__) + '/tasks/**/*.rb'].each { |f| load f }
10
+ Dir[File.dirname(__FILE__) + '/tasks/**/*.rake'].each { |f| Rake.application.add_import(f) }
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module NanocFuel
4
+ VERSION = '0.0.5'
5
+ end
data/lib/nanoc_fuel.rb ADDED
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ # Load requirements
4
+ require 'nanoc3'
5
+
6
+ # Load nanoc-fuel
7
+ require 'nanoc-fuel/base'
8
+ require 'nanoc-fuel/filters'
9
+ require 'nanoc-fuel/helpers'
10
+ require 'nanoc-fuel/version'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nanoc-fuel/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nanoc-fuel"
7
+ s.version = NanocFuel::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jack Chu", "Bob Whitney"]
10
+ s.email = ["jack@jackchu.com", "robertj.whitney@gmail.com"]
11
+ s.homepage = "https://github.com/kamui/nanoc-fuel"
12
+ s.summary = %q{nanoc extension that adds useful helpers (facebook, google analytics, etc).}
13
+ s.description = %q{}
14
+
15
+ s.rubyforge_project = "nanoc-fuel"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency('nanoc', '>= 3.1.6')
23
+ s.add_runtime_dependency('haml', '>= 3.1.1')
24
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ class NanocFuel::Helpers::FacebookTest < MiniTest::Unit::TestCase
4
+ include NanocFuel::Helpers::Facebook
5
+
6
+ def test_fb_init
7
+
8
+ html = %q{
9
+ <div id='fb-root'></div>
10
+ <script type='text/javascript'>
11
+ //<![CDATA[
12
+ window.fbAsyncInit = function() {
13
+ FB.init({appId: '12345', status: true, cookie: true, xfbml: true});
14
+ fbInitHook();
15
+ FB.Canvas.setSize();
16
+ };
17
+
18
+ function fbInitHook() {}
19
+
20
+ function sizeChangeCallback() {
21
+ FB.Canvas.setSize();
22
+ }
23
+
24
+ (function() {
25
+ var e = document.createElement('script'); e.async = true;
26
+ e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
27
+ document.getElementById('fb-root').appendChild(e);
28
+ }());
29
+ //]]>
30
+ </script>
31
+ }
32
+ assert_equal compact(html), compact(fb_init('12345'))
33
+ end
34
+
35
+ def test_fb_comments
36
+ html = %q{
37
+ <fb:comments href='http://example.com' num_posts='10' width='520'></fb:comments>
38
+ }
39
+ assert_equal compact(html), compact(fb_comments('http://example.com', '10', '520'))
40
+ end
41
+
42
+ def test_fb_like_btn
43
+ html = %q{
44
+ <iframe allowTransparency='true' frameborder='0' scrolling='no' src='//www.facebook.com/plugins/like.php?href&amp;amp;send=true&amp;amp;layout=standard&amp;amp;width=450&amp;amp;show_faces=true&amp;amp;action=like&amp;amp;colorscheme=light&amp;amp;font&amp;amp;height=80' style='border:none; overflow:hidden; width:450px; height:80px;'></iframe>
45
+ }
46
+ assert_equal compact(html), compact(fb_like_btn("standard", "450", "true", "true"))
47
+ end
48
+
49
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class NanocFuel::Helpers::GoogleTest < MiniTest::Unit::TestCase
4
+ include NanocFuel::Helpers::Google
5
+ def test_ga_tracking
6
+ html = %q{
7
+ <script type='text/javascript'>
8
+ //<![CDATA[
9
+ var _gaq = _gaq || [];
10
+ _gaq.push(['_setAccount', 'UA-12345']);
11
+ _gaq.push(['_trackPageview']);
12
+
13
+ (function() {
14
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
15
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
16
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
17
+ })();
18
+ //]]>
19
+ </script>
20
+ }
21
+ assert_equal compact(html), compact(ga_tracking('UA-12345'))
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'nanoc-fuel'
2
+ require 'minitest/autorun'
3
+ require 'nanoc3'
4
+
5
+ def compact(string)
6
+ compact_string = ''
7
+ string.each_line {|l| compact_string << l.strip }
8
+ compact_string
9
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-fuel
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.5
6
+ platform: ruby
7
+ authors:
8
+ - Jack Chu
9
+ - Bob Whitney
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-05-27 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: nanoc
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 3.1.6
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: haml
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 3.1.1
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: ""
39
+ email:
40
+ - jack@jackchu.com
41
+ - robertj.whitney@gmail.com
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ extra_rdoc_files: []
47
+
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - lib/nanoc-fuel/base.rb
56
+ - lib/nanoc-fuel/filters.rb
57
+ - lib/nanoc-fuel/helpers.rb
58
+ - lib/nanoc-fuel/helpers/facebook.rb
59
+ - lib/nanoc-fuel/helpers/google.rb
60
+ - lib/nanoc-fuel/helpers/rule_templates.rb
61
+ - lib/nanoc-fuel/helpers/rule_templates/base
62
+ - lib/nanoc-fuel/helpers/templates/facebook/fb_comments.haml
63
+ - lib/nanoc-fuel/helpers/templates/facebook/fb_init.haml
64
+ - lib/nanoc-fuel/helpers/templates/facebook/fb_like_btn.haml
65
+ - lib/nanoc-fuel/helpers/templates/google/ga_tracking_code.haml
66
+ - lib/nanoc-fuel/tasks.rb
67
+ - lib/nanoc-fuel/version.rb
68
+ - lib/nanoc_fuel.rb
69
+ - nanoc-fuel.gemspec
70
+ - test/helpers/facebook_test.rb
71
+ - test/helpers/google_test.rb
72
+ - test/test_helper.rb
73
+ homepage: https://github.com/kamui/nanoc-fuel
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project: nanoc-fuel
96
+ rubygems_version: 1.8.4
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: nanoc extension that adds useful helpers (facebook, google analytics, etc).
100
+ test_files:
101
+ - test/helpers/facebook_test.rb
102
+ - test/helpers/google_test.rb
103
+ - test/test_helper.rb