jekyll-eztags 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 39cb3659d2375f563dd238431829c19c588cbc0b
4
+ data.tar.gz: 42f8a6a40f5c6822553a3921c97c8ce54cd6804b
5
+ SHA512:
6
+ metadata.gz: a5ef5310789c9fdcda23396f8f15aa8f70bd545e06da9e8dfdca0d948920d19145b4e12aac15a6dea38a17e001055dcbb2595cb7ab6ed0189e08f39a57a2c207
7
+ data.tar.gz: f93e3df990dee6a135eca60d23bfa69432b5fab22fa133172163b14c52f7264259e90a3d84427d610728cdd46fb739c6978be1e32416ad3c33681ca67ebb9aaa
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jerzy J. Gangi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # Jekyll::Eztags
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jekyll-eztags'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jekyll-eztags
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/jekyll-eztags/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+
32
+
33
+ = jekyll-eztagging
34
+
35
+ By Jerzy J. Gangi <mailto:eilermann@lavabit.com>, based on the Jekyll-Tagging gem by Arne Eilermann and Jens Wille
36
+
37
+ jekyll-eztagging is a Jekyll plugin, to add a tag cloud and per tag pages plus feeds to your Jekyll generated Website.
38
+
39
+ == Usage
40
+
41
+ Install it:
42
+
43
+ gem install jekyll-tagging
44
+
45
+ Add the following to your <tt>_plugins/ext.rb</tt> file:
46
+
47
+ require 'jekyll/tagging'
48
+
49
+ And in your <tt>_config.yml</tt> you have to define your layout used to generate tag pages like:
50
+
51
+ tag_page_layout: tag_page
52
+ tag_page_dir: tag
53
+
54
+ 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. Furthermore, you got a <tt>tags</tt> filter which you can feed withe a <tt>post</tt> or a <tt>site</tt> object to get a link list of all its tags.
55
+
56
+ You can optionally define a per tag Atom/RSS feed. In your <tt>_config.yml</tt> define the following:
57
+
58
+ tag_feed_layout: tag_feed
59
+ tag_feed_dir: tag
60
+
61
+ (<tt>tag_page_dir</tt> and <tt>tag_feed_dir</tt> can have the same value.)
62
+
63
+
64
+ === Ignoring tags
65
+
66
+ Sometimes you don't want tag pages generated for certain pages. That's ok! Just add <tt>ignored_tags: [tags,to,ignore]</tt> to your <tt>_config.yml</tt>
67
+ === Example tag page layout
68
+
69
+ ---
70
+ layout: default
71
+ ---
72
+ <h2>{{ page.tag }}</h2>
73
+ <ul>
74
+ {% for post in page.posts %}
75
+ <li><a href="{{ post.url }}">{{ post.title }}</a> ({{ post.date | date_to_string }} | Tags: {{ post | tags }})</li>
76
+ {% endfor %}
77
+ </ul>
78
+
79
+ <div id="tag-cloud">
80
+ {{ site | tag_cloud }}
81
+ </div>
82
+
83
+
84
+ === Example layout of an Atom feed
85
+
86
+ ---
87
+ layout: nil
88
+ ---
89
+ <?xml version="1.0" encoding="utf-8"?>
90
+ <feed xmlns="http://www.w3.org/2005/Atom">
91
+ <title>Your Title - {{ page.tag }}</title>
92
+ <link href="http://example.com{{ page.url }}" rel="self"/>
93
+ <link href="http://example.com/tag/{{ page.tag }}.html"/>
94
+ <updated>{{ site.time | date_to_xmlschema }}</updated>
95
+ <id>http://example.com/tag/{{ page.tag }}.html</id>
96
+ <author>
97
+ <name>Author Here</name>
98
+ </author>
99
+ {% for post in page.posts %}
100
+ <entry>
101
+ <title>{{ post.title }}</title>
102
+ <link href="http://example.com{{ post.url }}"/>
103
+ <updated>{{ post.date | date_to_xmlschema }}</updated>
104
+ <id>http://example.com{{ post.id }}</id>
105
+ <content type="html">{{ post.content | xml_escape }}</content>
106
+ </entry>
107
+ {% endfor %}
108
+ </feed>
109
+
110
+ == Links
111
+
112
+ <b></b>
113
+ Documentation:: <http://rubydoc.info/gems/jekyll-tagging/frames>
114
+ Source code:: <http://github.com/pattex/jekyll-tagging>
115
+ RubyGem:: <http://rubygems.org/gems/jekyll-tagging>
116
+
117
+ == License
118
+
119
+ === The MIT License
120
+
121
+ Copyright (c) 2010-2012 University of Cologne,
122
+ Albertus-Magnus-Platz, 50923 Cologne, Germany
123
+
124
+ Permission is hereby granted, free of charge, to any person obtaining a copy
125
+ of this software and associated documentation files (the "Software"), to deal
126
+ in the Software without restriction, including without limitation the rights
127
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
128
+ copies of the Software, and to permit persons to whom the Software is
129
+ furnished to do so, subject to the following conditions:
130
+
131
+ The above copyright notice and this permission notice shall be included in
132
+ all copies or substantial portions of the Software.
133
+
134
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
135
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
136
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
137
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
138
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
139
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
140
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require File.expand_path(%q{../lib/jekyll/tagging/version}, __FILE__)
3
+
4
+ begin
5
+ require 'hen'
6
+
7
+ Hen.lay! {{
8
+ :gem => {
9
+ :name => %q{jekyll-tagging},
10
+ :version => Jekyll::Tagging::VERSION,
11
+ :summary => %q{Jekyll plugin to automatically generate a tag cloud and tag pages.},
12
+ :authors => ['Arne Eilermann', 'Jens Wille'],
13
+ :email => ['eilermann@lavabit.com', 'jens.wille@uni-koeln.de'],
14
+ :license => %q{MIT},
15
+ :homepage => :pattex,
16
+ :dependencies => %w[ruby-nuggets]
17
+ }
18
+ }}
19
+ rescue LoadError => err
20
+ warn "Please install the `hen' gem. (#{err})"
21
+ end
22
+
23
+ begin
24
+ require 'jekyll/testtasks/rake'
25
+ rescue LoadError => err
26
+ warn "Please install the `jekyll-testtasks' gem. (#{err})"
27
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module Eztags
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,126 @@
1
+ require 'nuggets/range/quantile'
2
+ require 'erb'
3
+ require "jekyll/eztags/version"
4
+
5
+ module Jekyll
6
+ module Eztags
7
+ # Your code goes here...
8
+ end
9
+ class Tagger < Generator
10
+
11
+ safe true
12
+
13
+ attr_accessor :site
14
+
15
+ @types = [:page, :feed]
16
+
17
+ class << self; attr_accessor :types, :site; end
18
+
19
+ def generate(site)
20
+ self.class.site = self.site = site
21
+
22
+ generate_tag_pages
23
+ add_tag_cloud
24
+ end
25
+
26
+ private
27
+
28
+ # Generates a page per tag and adds them to all the pages of +site+.
29
+ # A <tt>tag_page_layout</tt> have to be defined in your <tt>_config.yml</tt>
30
+ # to use this.
31
+ def generate_tag_pages
32
+ active_tags.each { |tag, posts| new_tag(tag, posts) }
33
+ end
34
+
35
+ def new_tag(tag, posts)
36
+ self.class.types.each { |type|
37
+ if layout = site.config["tag_#{type}_layout"]
38
+ data = { 'layout' => layout, 'posts' => posts.sort.reverse! }
39
+
40
+ name = yield data if block_given?
41
+
42
+ site.pages << TagPage.new(
43
+ site, site.source, site.config["tag_#{type}_dir"],
44
+ "#{name || tag}#{site.layouts[data['layout']].ext}", data
45
+ )
46
+ end
47
+ }
48
+ end
49
+
50
+ def add_tag_cloud(num = 5, name = 'tag_data')
51
+ s, t = site, { name => calculate_tag_cloud(num) }
52
+ s.respond_to?(:add_payload) ? s.add_payload(t) : s.config.update(t)
53
+ end
54
+
55
+ # Calculates the css class of every tag for a tag cloud. The possible
56
+ # classes are: set-1..set-5.
57
+ #
58
+ # [[<TAG>, <CLASS>], ...]
59
+ def calculate_tag_cloud(num = 5)
60
+ range = 0
61
+
62
+ tags = active_tags.map { |tag, posts|
63
+ [tag.to_s, range < (size = posts.size) ? range = size : size]
64
+ }
65
+
66
+
67
+ range = 1..range
68
+
69
+ tags.sort!.map! { |tag, size| [tag, range.quantile(size, num)] }
70
+ end
71
+
72
+ def active_tags
73
+ return site.tags unless site.config["ignored_tags"]
74
+ site.tags.reject { |t| site.config["ignored_tags"].include? t[0] }
75
+ end
76
+
77
+ end
78
+
79
+ class TagPage < Page
80
+
81
+ def initialize(site, base, dir, name, data = {})
82
+ self.content = data.delete('content') || ''
83
+ self.data = data
84
+
85
+ super(site, base, dir[-1, 1] == '/' ? dir : '/' + dir, name)
86
+
87
+ data['tag'] ||= basename
88
+ end
89
+
90
+ def read_yaml(*)
91
+ # Do nothing
92
+ end
93
+
94
+ end
95
+
96
+ module Filters
97
+
98
+ def tag_cloud(site)
99
+ active_tag_data.map { |tag, set|
100
+ tag_link(tag, tag_url(tag), :class => "set-#{set}")
101
+ }.join(' ')
102
+ end
103
+
104
+ def tag_link(tag, url = tag_url(tag), html_opts = nil)
105
+ html_opts &&= ' ' << html_opts.map { |k, v| %Q{#{k}="#{v}"} }.join(' ')
106
+ %Q{<a href="#{url}"#{html_opts}>#{tag}</a>}
107
+ end
108
+
109
+ def tag_url(tag, type = :page, site = Tagger.site)
110
+ url = File.join('', site.config["tag_#{type}_dir"], ERB::Util.u(tag))
111
+ site.permalink_style == :pretty ? url : url << '.html'
112
+ end
113
+
114
+ def tags(obj)
115
+ tags = obj['tags'].dup
116
+ tags.map! { |t| t.first } if tags.first.is_a?(Array)
117
+ tags.map! { |t| tag_link(t, tag_url(t), :rel => 'tag') if t.is_a?(String) }.compact!
118
+ tags.join(', ')
119
+ end
120
+
121
+ def active_tag_data(site = Tagger.site)
122
+ return site.config['tag_data'] unless site.config["ignored_tags"]
123
+ site.config["tag_data"].reject { |tag, set| site.config["ignored_tags"].include? tag }
124
+ end
125
+ end
126
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-eztags
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jerzy J. Gangi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-nuggets
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A very simple Jekyll plugin to automatically generate tag pages. No fancy
56
+ features.
57
+ email:
58
+ - jerzygangi@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - lib/jekyll/eztags.rb
67
+ - lib/jekyll/eztags/version.rb
68
+ homepage: http://github.com/jerzygangi/jekyll-eztags
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.2.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Jekyll plugin to automatically generate tag pages
92
+ test_files: []