jekyll-tagging 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog ADDED
@@ -0,0 +1,3 @@
1
+ == 0.0.1 [2010-10-25]
2
+
3
+ * Here I am!
data/README.rdoc ADDED
@@ -0,0 +1,69 @@
1
+ = jekyll-tagging
2
+
3
+ By Arne Eilermann <mailto:eilermann@lavabit.com> and Jens Wille <mailto:jens.wille@uni-koeln.de>
4
+
5
+ jekyll-tagging is a Jekyll plugin, to add a tag cloud and per tag pages to your Jekyll generated Website.
6
+
7
+ == Usage
8
+
9
+ Install it:
10
+
11
+ sudo gem install jekyll-tagging
12
+
13
+ Add the following to your <tt>_plugins/ext.rb</tt> file:
14
+
15
+ require 'jekyll/tagging'
16
+
17
+ And in your <tt>_config.yml</tt> you have to define your layout used to generate tag pages like:
18
+
19
+ tag_page_layout: tag_page
20
+ tag_page_dir: tag
21
+
22
+ Now you got a new filter called <tt>tag_cloud</tt> which you can use with the <tt>site</tt> object as argument in your layout to get a cloud of all your site's tags. The tags are linked to their related tag page.
23
+
24
+ === Example tag page layout
25
+
26
+ ---
27
+ layout: default
28
+ ---
29
+ <h2>{{ page.tag }}</h2>
30
+ <ul>
31
+ {% for post in page.posts %}
32
+ <li><a href="{{ post.url }}">{{ post.title }}</a> ({{ post.date | date_to_string }})</li>
33
+ {% endfor %}
34
+ </ul>
35
+
36
+ <div id="tag-cloud">
37
+ {{ site | tag_cloud }}
38
+ </div>
39
+
40
+ == Links
41
+
42
+ <b></b>
43
+ Documentation:: <http://rdoc.info/github/pattex/jekyll-tagging>
44
+ Source code:: <http://github.com/pattex/jekyll-tagging>
45
+ RubyGem:: <http://rubygems.org/gems/jekyll-tagging>
46
+
47
+ == License
48
+
49
+ === The MIT License
50
+
51
+ Copyright (c) 2010 Arne Eilermann
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining a copy
54
+ of this software and associated documentation files (the "Software"), to deal
55
+ in the Software without restriction, including without limitation the rights
56
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57
+ copies of the Software, and to permit persons to whom the Software is
58
+ furnished to do so, subject to the following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be included in
61
+ all copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
69
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require %q{lib/jekyll/tagging/version}
2
+
3
+ begin
4
+ require 'hen'
5
+
6
+ Hen.lay! {{
7
+ :gem => {
8
+ :name => %q{jekyll-tagging},
9
+ :version => Jekyll::Tagging::VERSION,
10
+ :summary => %q{Jekyll plugin to automatically generate a tag cloud and tag pages.},
11
+ :files => FileList['lib/**/*.rb'].to_a,
12
+ :extra_files => FileList['[A-Z]*'].to_a,
13
+ :dependencies => %w[ruby-nuggets],
14
+ :authors => ['Arne Eilermann', 'Jens Wille'],
15
+ :email => ['eilermann@lavabit.com', 'jens.wille@uni-koeln.de'],
16
+ :homepage => %q{http://github.com/pattex/jekyll-tagging}
17
+ }
18
+ }}
19
+ rescue LoadError
20
+ warn "Please install the `hen' gem."
21
+ end
22
+
23
+ ### Place your custom Rake tasks here.
24
+
25
+ begin
26
+ require 'jekyll/testtasks/rake'
27
+ rescue LoadError
28
+ warn "Please install the `jekyll-testtasks' gem."
29
+ end
@@ -0,0 +1,82 @@
1
+ require 'nuggets/range/quantile_mixin'
2
+ require 'erb'
3
+
4
+ class Range
5
+ include Nuggets::Range::QuantileMixin
6
+ end
7
+
8
+ module Jekyll
9
+
10
+ class Tagger < Generator
11
+
12
+ safe true
13
+
14
+ def generate(site)
15
+ @tag_page_dir = site.config['tag_page_dir'] || 'tag'
16
+ @tag_page_layout = site.config['tag_page_layout']
17
+
18
+ generate_tag_pages(site) if @tag_page_layout
19
+ site.config.update({ 'tag_data' => calculate_tag_cloud(site) })
20
+ end
21
+
22
+ # Generates a page per tag and adds them to all the pages of +site+.
23
+ # A <tt>tag_page_layout</tt> have to be defined in your <tt>_config.yml</tt>
24
+ # to use this.
25
+ def generate_tag_pages(site)
26
+ site.tags.each { |t|
27
+ site.pages << new_tag_page(site, site.source, @tag_page_dir, t[0], t[1])
28
+ }
29
+ end
30
+
31
+ def new_tag_page(site, base, dir, tag, posts)
32
+ TagPage.new(site, base, dir, "#{tag}.html", {
33
+ 'layout' => @tag_page_layout,
34
+ 'posts' => posts,
35
+ })
36
+ end
37
+
38
+ # Calculates the css class of every tag for a tag cloud. The possible
39
+ # classes are: set-1..set-5.
40
+ #
41
+ # [[<TAG>, <CLASS>], ...]
42
+ def calculate_tag_cloud(site)
43
+ tag_data = []
44
+ max = site.tags.map { |t| t[1].size }.max
45
+ site.tags.sort.each { |t|
46
+ quant = (1..max).quantile(t[1].size, 5)
47
+ tag_data << [t[0], "set-#{quant}"]
48
+ }
49
+ tag_data
50
+ end
51
+
52
+ end
53
+
54
+ class TagPage < Page
55
+ def initialize(site, base, dir, name, data = {})
56
+ self.content = data.delete('content') || ''
57
+ self.data = data
58
+
59
+ dir = dir[-1, 1] == '/' ? dir : '/' + dir
60
+
61
+ super(site, base, dir, name)
62
+
63
+ self.data['tag'] = basename
64
+ end
65
+
66
+ def read_yaml(_, __)
67
+ # Do nothing
68
+ end
69
+
70
+ end
71
+
72
+ module Filters
73
+
74
+ def tag_cloud(site)
75
+ site['tag_data'].collect { |t|
76
+ "<a href=\"/#{site['tag_page_dir']}/#{ERB::Util.u(t[0])}.html\" class=\"#{t[1]}\">#{t[0]}</a>"
77
+ }.join(' ')
78
+ end
79
+
80
+ end
81
+
82
+ end
@@ -0,0 +1,31 @@
1
+ module Jekyll
2
+
3
+ module Tagging
4
+
5
+ module Version
6
+
7
+ MAJOR = 0
8
+ MINOR = 0
9
+ TINY = 1
10
+
11
+ class << self
12
+
13
+ # Returns array representation.
14
+ def to_a
15
+ [MAJOR, MINOR, TINY]
16
+ end
17
+
18
+ # Short-cut for version string.
19
+ def to_s
20
+ to_a.join('.')
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ VERSION = Version.to_s
28
+
29
+ end
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-tagging
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Arne Eilermann
14
+ - Jens Wille
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-27 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: ruby-nuggets
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Jekyll plugin to automatically generate a tag cloud and tag pages.
37
+ email:
38
+ - eilermann@lavabit.com
39
+ - jens.wille@uni-koeln.de
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - ChangeLog
46
+ - README.rdoc
47
+ files:
48
+ - lib/jekyll/tagging/version.rb
49
+ - lib/jekyll/tagging.rb
50
+ - Rakefile
51
+ - README.rdoc
52
+ - ChangeLog
53
+ has_rdoc: true
54
+ homepage: http://github.com/pattex/jekyll-tagging
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --line-numbers
60
+ - --inline-source
61
+ - --charset
62
+ - UTF-8
63
+ - --title
64
+ - jekyll-tagging Application documentation
65
+ - --all
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Jekyll plugin to automatically generate a tag cloud and tag pages.
93
+ test_files: []
94
+