jekyll-categories 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ require 'jekyll-categories/tags'
2
+
1
3
  module Jekyll
2
4
  module Categories
3
5
  class CategoryIndex < Page
@@ -0,0 +1,121 @@
1
+ module Jekyll
2
+ module Categories
3
+ class TagIndex < Page
4
+ def initialize(site, base, dir, tag)
5
+ @site = site
6
+ @base = base
7
+ @dir = dir
8
+ @name = 'index.html'
9
+
10
+ self.process(@name)
11
+ self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
12
+ self.data['tag'] = tag
13
+
14
+ tag_title_prefix = site.config['tag_title_prefix'] || 'Tag: '
15
+ self.data['title'] = "#{tag_title_prefix}#{tag}"
16
+ end
17
+ end
18
+
19
+ class TagFeed < Page
20
+ def initialize(site, base, dir, tag)
21
+ @site = site
22
+ @base = base
23
+ @dir = dir
24
+ @name = 'atom.xml'
25
+
26
+ self.process(@name)
27
+ self.read_yaml(File.join(base, '_layouts'), 'tag_feed.xml')
28
+ self.data['tag'] = tag
29
+
30
+ tag_title_prefix = site.config['tag_title_prefix'] || 'Tag: '
31
+ self.data['title'] = "#{tag_title_prefix}#{tag}"
32
+ end
33
+ end
34
+
35
+ class TagList < Page
36
+ def initialize(site, base, dir, tags)
37
+ @site = site
38
+ @base = base
39
+ @dir = dir
40
+ @name = 'index.html'
41
+
42
+ self.process(@name)
43
+ self.read_yaml(File.join(base, '_layouts'), 'tag_list.html')
44
+ self.data['tags'] = tags
45
+ end
46
+ end
47
+
48
+ class TagGenerator < Generator
49
+ safe true
50
+
51
+ def generate(site)
52
+ if site.layouts.key? 'tag_index'
53
+ dir = site.config['tag_dir'] || 'tags'
54
+ site.tags.keys.each do |tag|
55
+ write_tag_index(site, File.join(dir, tag.gsub(/\s/, "-").gsub(/[^\w-]/, '').downcase), tag)
56
+ end
57
+ end
58
+
59
+ if site.layouts.key? 'tag_feed'
60
+ dir = site.config['tag_dir'] || 'tags'
61
+ site.tags.keys.each do |tag|
62
+ write_tag_feed(site, File.join(dir, tag.gsub(/\s/, "-").gsub(/[^\w-]/, '').downcase), tag)
63
+ end
64
+ end
65
+
66
+ if site.layouts.key? 'tag_list'
67
+ dir = site.config['tag_dir'] || 'tags'
68
+ write_tag_list(site, dir, site.tags.keys.sort)
69
+ end
70
+ end
71
+
72
+ def write_tag_index(site, dir, tag)
73
+ index = TagIndex.new(site, site.source, dir, tag)
74
+ index.render(site.layouts, site.site_payload)
75
+ index.write(site.dest)
76
+ site.static_files << index
77
+ end
78
+
79
+ def write_tag_feed(site, dir, tag)
80
+ index = TagFeed.new(site, site.source, dir, tag)
81
+ index.render(site.layouts, site.site_payload)
82
+ index.write(site.dest)
83
+ site.static_files << index
84
+ end
85
+
86
+ def write_tag_list(site, dir, tags)
87
+ index = TagList.new(site, site.source, dir, tags)
88
+ index.render(site.layouts, site.site_payload)
89
+ index.write(site.dest)
90
+ site.static_files << index
91
+ end
92
+ end
93
+
94
+ # Returns a correctly formatted tag url based on site configuration.
95
+ #
96
+ # Use without arguments to return the url of the tag list page.
97
+ # {% tag_url %}
98
+ #
99
+ # Use with argument to return the url of a specific catogory page. The
100
+ # argument can be either a string or a variable in the current context.
101
+ # {% tag_url tag_name %}
102
+ # {% tag_url tag_var %}
103
+ #
104
+ class TagUrlTag < Liquid::Tag
105
+ def initialize(tag_name, text, tokens)
106
+ super
107
+ @tag = text
108
+ end
109
+
110
+ def render(context)
111
+ base_url = context.registers[:site].config['base-url'] || '/'
112
+ tag_dir = context.registers[:site].config['tag_dir'] || 'tags'
113
+
114
+ tag = context[@tag] || @tag.strip.tr(' ', '-').downcase
115
+ tag.empty? ? "#{base_url}#{tag_dir}" : "#{base_url}#{tag_dir}/#{tag}"
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ Liquid::Template.register_tag('tag_url', Jekyll::Categories::TagUrlTag)
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Categories
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,85 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jekyll-categories
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
12
- - "Roger L\xC3\xB3pez"
7
+ authors:
8
+ - Roger López
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-06-30 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: jekyll
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 10
31
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
32
21
  version: 0.10.0
33
22
  type: :runtime
34
- version_requirements: *id001
35
- description: Provides a category index page, category pages and category atom feeds for Jekyll.
36
- email:
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.0
30
+ description: Provides a category index page, category pages and category atom feeds
31
+ for Jekyll.
32
+ email:
37
33
  - roger@zroger.com
38
34
  executables: []
39
-
40
35
  extensions: []
41
-
42
36
  extra_rdoc_files: []
43
-
44
- files:
37
+ files:
45
38
  - .gitignore
46
39
  - Gemfile
47
40
  - Rakefile
48
41
  - jekyll-categories.gemspec
49
42
  - lib/jekyll-categories.rb
43
+ - lib/jekyll-categories/tags.rb
50
44
  - lib/jekyll-categories/version.rb
51
45
  - readme.md
52
- has_rdoc: true
53
46
  homepage: http://github.com/zroger/jekyll-categories
54
47
  licenses: []
55
-
56
48
  post_install_message:
57
49
  rdoc_options: []
58
-
59
- require_paths:
50
+ require_paths:
60
51
  - lib
61
- required_ruby_version: !ruby/object:Gem::Requirement
52
+ required_ruby_version: !ruby/object:Gem::Requirement
62
53
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
59
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- segments:
75
- - 0
76
- version: "0"
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
77
64
  requirements: []
78
-
79
65
  rubyforge_project: jekyll-categories
80
- rubygems_version: 1.3.7
66
+ rubygems_version: 1.8.23
81
67
  signing_key:
82
68
  specification_version: 3
83
69
  summary: Category generators for Jekyll
84
70
  test_files: []
85
-