alula 0.4.13 → 0.4.14

Sign up to get free protection for your applications and to get access to all the features.
data/lib/alula/content.rb CHANGED
@@ -4,6 +4,9 @@ require 'alula/contents/attachment'
4
4
 
5
5
  module Alula
6
6
  class Content
7
+ attr_reader :site
8
+ attr_reader :config
9
+
7
10
  attr_reader :pages
8
11
  attr_reader :posts
9
12
  attr_reader :attachments
@@ -11,6 +14,7 @@ module Alula
11
14
 
12
15
  def initialize(opts = {})
13
16
  @site = opts.delete(:site)
17
+ @config = @site.config
14
18
 
15
19
  @pages = []
16
20
  @posts = []
@@ -25,6 +29,10 @@ module Alula
25
29
 
26
30
  # Generate our dynamic content (pages, categories, archives, etc. etc.)
27
31
  generate_content
32
+
33
+ # Write slugs to config
34
+ self.config.slugs = (@posts + @pages).collect{|c| c.metadata.slug}
35
+ self.config.slugs.count
28
36
  end
29
37
 
30
38
  def method_missing(meth, *args, &blk)
@@ -289,9 +289,25 @@ module Alula
289
289
  end
290
290
 
291
291
  def previous(locale = nil)
292
+ if self.navigation
293
+ pos = self.navigation(locale).index(self)
294
+ if pos and pos < (self.navigation(locale).count - 1)
295
+ self.navigation(locale)[pos + 1]
296
+ else
297
+ nil
298
+ end
299
+ end
292
300
  end
293
301
 
294
302
  def next(locale = nil)
303
+ if self.navigation
304
+ pos = self.navigation(locale).index(self)
305
+ if pos and pos > 0
306
+ self.navigation(locale)[pos - 1]
307
+ else
308
+ nil
309
+ end
310
+ end
295
311
  end
296
312
 
297
313
  def navigation(locale = nil)
@@ -5,24 +5,6 @@ module Alula
5
5
  class Post < Item
6
6
  has_payload
7
7
 
8
- def previous(locale = nil)
9
- pos = self.navigation(locale).index(self)
10
- if pos and pos < (self.navigation(locale).count - 1)
11
- self.navigation(locale)[pos + 1]
12
- else
13
- nil
14
- end
15
- end
16
-
17
- def next(locale = nil)
18
- pos = self.navigation(locale).index(self)
19
- if pos and pos > 0
20
- self.navigation(locale)[pos - 1]
21
- else
22
- nil
23
- end
24
- end
25
-
26
8
  def navigation(locale = nil)
27
9
  locale ||= self.current_locale || self.site.config.locale
28
10
  @navigation[locale] ||= self.site.content.posts.select { |item| item.languages.include?(locale) }
@@ -38,6 +38,19 @@ module Alula
38
38
  def allow_compressing?
39
39
  :high
40
40
  end
41
+
42
+ protected
43
+ def fetch_languages
44
+ languages = {}
45
+ self.site.content.posts.each do |post|
46
+ post.languages.each do |lang|
47
+ languages[lang] ||= []
48
+ languages[lang] << post
49
+ end
50
+ end
51
+ languages
52
+ end
53
+
41
54
  end
42
55
  end
43
56
 
@@ -2,13 +2,14 @@ module Alula
2
2
  class Archive < Generator
3
3
  def generate
4
4
  # Loop all languages and count posts per language
5
- @languages = {}
6
- self.site.content.posts.each do |post|
7
- post.languages.each do |lang|
8
- @languages[lang] ||= []
9
- @languages[lang] << post
10
- end
11
- end
5
+ @languages = fetch_languages
6
+ # @languages = {}
7
+ # self.site.content.posts.each do |post|
8
+ # post.languages.each do |lang|
9
+ # @languages[lang] ||= []
10
+ # @languages[lang] << post
11
+ # end
12
+ # end
12
13
 
13
14
  titles = Hash[@languages.collect {|lang, x| [lang, I18n.t("archive.title", locale: lang)]}]
14
15
 
@@ -40,22 +41,22 @@ module Alula
40
41
  view: "archive",
41
42
  key: archive[:key],
42
43
  },
43
- :previous => ->(hook, locale = nil) {
44
- pos = self.navigation(locale).index(self)
45
- if pos and pos < (self.navigation(locale).count - 1)
46
- self.navigation(locale)[pos + 1]
47
- else
48
- nil
49
- end
50
- },
51
- :next => ->(hook, locale = nil) {
52
- pos = self.navigation(locale).index(self)
53
- if pos and pos > 0
54
- self.navigation(locale)[pos - 1]
55
- else
56
- nil
57
- end
58
- },
44
+ # :previous => ->(hook, locale = nil) {
45
+ # pos = self.navigation(locale).index(self)
46
+ # if pos and pos < (self.navigation(locale).count - 1)
47
+ # self.navigation(locale)[pos + 1]
48
+ # else
49
+ # nil
50
+ # end
51
+ # },
52
+ # :next => ->(hook, locale = nil) {
53
+ # pos = self.navigation(locale).index(self)
54
+ # if pos and pos > 0
55
+ # self.navigation(locale)[pos - 1]
56
+ # else
57
+ # nil
58
+ # end
59
+ # },
59
60
  :navigation => ->(hook, locale = nil) {
60
61
  locale ||= self.current_locale || self.site.config.locale
61
62
  @navigation[locale] ||= self.site.content.pages.select { |item|
@@ -2,13 +2,14 @@ module Alula
2
2
  class Paginate < Generator
3
3
  def generate
4
4
  # Loop all languages and count posts per language
5
- @languages = {}
6
- self.site.content.posts.each do |post|
7
- post.languages.each do |lang|
8
- @languages[lang] ||= []
9
- @languages[lang] << post
10
- end
11
- end
5
+ @languages = fetch_languages
6
+ # @languages = {}
7
+ # self.site.content.posts.each do |post|
8
+ # post.languages.each do |lang|
9
+ # @languages[lang] ||= []
10
+ # @languages[lang] << post
11
+ # end
12
+ # end
12
13
 
13
14
  # Maximum amount of posts
14
15
  num_posts = self.site.content.posts.count
@@ -39,22 +40,22 @@ module Alula
39
40
  site: self.site,
40
41
  view: self.options.view || "paginate",
41
42
  },
42
- :previous => ->(hook, locale = nil) {
43
- pos = self.navigation(locale).index(self)
44
- if pos and pos < (self.navigation(locale).count - 1)
45
- self.navigation(locale)[pos + 1]
46
- else
47
- nil
48
- end
49
- },
50
- :next => ->(hook, locale = nil) {
51
- pos = self.navigation(locale).index(self)
52
- if pos and pos > 0
53
- self.navigation(locale)[pos - 1]
54
- else
55
- nil
56
- end
57
- },
43
+ # :previous => ->(hook, locale = nil) {
44
+ # pos = self.navigation(locale).index(self)
45
+ # if pos and pos < (self.navigation(locale).count - 1)
46
+ # self.navigation(locale)[pos + 1]
47
+ # else
48
+ # nil
49
+ # end
50
+ # },
51
+ # :next => ->(hook, locale = nil) {
52
+ # pos = self.navigation(locale).index(self)
53
+ # if pos and pos > 0
54
+ # self.navigation(locale)[pos - 1]
55
+ # else
56
+ # nil
57
+ # end
58
+ # },
58
59
  :navigation => ->(hook, locale = nil) {
59
60
  locale ||= self.current_locale || self.site.config.locale
60
61
  @navigation[locale] ||= self.site.content.pages.select { |item| item.metadata.generator == self.generator and item.languages.include?(locale) }
data/lib/alula/version.rb CHANGED
@@ -2,7 +2,7 @@ module Alula
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- PATCH = 13
5
+ PATCH = 14
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alula
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.13
4
+ version: 0.4.14
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-08-11 00:00:00.000000000 Z
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -502,3 +502,4 @@ signing_key:
502
502
  specification_version: 3
503
503
  summary: Alula is simple, static blog generator.
504
504
  test_files: []
505
+ has_rdoc: