alula 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.6
1
+ 0.4.7
@@ -5,12 +5,20 @@ require 'htmlcompressor'
5
5
  module Alula
6
6
  class Compressors
7
7
  class DummyCompressor
8
+ def compresses?(item)
9
+ return false
10
+ end
11
+
8
12
  def compress(content)
9
13
  content
10
14
  end
11
15
  end
12
16
 
13
17
  class CSSCompressor
18
+ def compresses?(item)
19
+ return true
20
+ end
21
+
14
22
  def compress(content)
15
23
  if content.count("\n") > 2
16
24
  Sass::Engine.new(content,
@@ -29,6 +37,10 @@ module Alula
29
37
  @compressor = Uglifier.new
30
38
  end
31
39
 
40
+ def compresses?(item)
41
+ return true
42
+ end
43
+
32
44
  def compress(content)
33
45
  @compressor.compress(content)
34
46
  end
@@ -36,13 +48,72 @@ module Alula
36
48
 
37
49
  class HTMLCompressor
38
50
  def initialize
39
- @compressor = HtmlCompressor::Compressor.new({
40
- remove_surrounding_spaces: HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source",
41
- })
51
+ HtmlCompressor::Compressor.send(:include, HTMLCompressorExt)
52
+ @compressor = HtmlCompressor::Compressor.new
53
+ # remove_surrounding_spaces: HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script",
54
+ # remove_intertag_spaces: true,
55
+ # remove_quotes: true,
56
+ # remove_script_attributes: true,
57
+ # remove_style_attributes: true,
58
+ # remove_link_attributes: true,
59
+ # simple_boolean_attributes: true,
60
+ # remove_http_protocol: false,
61
+ # remove_https_protocol: false,
62
+ # })
63
+ @compressor.profile = :high
42
64
  end
43
65
 
44
- def compress(content)
66
+ def compresses?(item)
67
+ return true if item.generator.nil?
68
+
69
+ return item.generator.allow_compressing? != :none
70
+ end
71
+
72
+ def compress(item, content)
73
+ _old_profile = @compressor.profile
74
+ unless item.generator.nil?
75
+ @compressor.profile = item.generator.allow_compressing?
76
+ end
77
+
45
78
  @compressor.compress(content)
79
+ ensure
80
+ @compressor.profile = _old_profile
81
+ end
82
+
83
+ module HTMLCompressorExt
84
+ def profile
85
+ @profile
86
+ end
87
+
88
+ def profile=(profile)
89
+ @profile = profile
90
+ case profile
91
+ when :none
92
+ @options[:enabled] = false
93
+ when :normal
94
+ @options[:enabled] = true
95
+ @options[:remove_surrounding_spaces] = HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script"
96
+ @options[:remove_intertag_spaces] = true
97
+ @options[:remove_quotes] = false
98
+ @options[:remove_script_attributes] = true
99
+ @options[:remove_style_attributes] = true
100
+ @options[:remove_link_attributes] = true
101
+ @options[:simple_boolean_attributes] = true
102
+ @options[:remove_http_protocol] = false
103
+ @options[:remove_https_protocol] = false
104
+ when :high
105
+ @options[:enabled] = true
106
+ @options[:remove_surrounding_spaces] = HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script"
107
+ @options[:remove_intertag_spaces] = true
108
+ @options[:remove_quotes] = true
109
+ @options[:remove_script_attributes] = true
110
+ @options[:remove_style_attributes] = true
111
+ @options[:remove_link_attributes] = true
112
+ @options[:simple_boolean_attributes] = true
113
+ @options[:remove_http_protocol] = "href,src,cite,action,data-original,data-hires"
114
+ @options[:remove_https_protocol] = "href,src,cite,action,data-original,data-hires"
115
+ end
116
+ end
46
117
  end
47
118
  end
48
119
  end
data/lib/alula/config.rb CHANGED
@@ -42,7 +42,9 @@ module Alula
42
42
  # Tagline of the blog
43
43
  tagline: "This has no tagline.",
44
44
  # The author, default
45
- author: "John Doe",
45
+ author: "",
46
+ # The blog description
47
+ description: "",
46
48
  # The host where blog is available
47
49
  url: "http://localhost:3000",
48
50
 
@@ -85,21 +87,28 @@ module Alula
85
87
  content: {
86
88
  generators: {
87
89
  paginate: {
88
- items: 10,
90
+ items: 10,
89
91
  template: "/:locale/page/:page/",
90
92
  },
91
93
  feedbuilder: {
92
- items: 10,
93
- name: "feed.xml",
94
- slug: "feed",
94
+ items: 10,
95
+ name: "feed.xml",
96
+ slug: "feed",
95
97
  template: "/:locale/:name",
96
98
  },
97
- sitemap: {}
99
+ sitemap: {},
100
+ archive: {
101
+ template: "/:locale/:name/",
102
+ templates: [
103
+ "/:year/",
104
+ "/:year/:month/",
105
+ ],
106
+ },
98
107
  },
99
108
  filters: {
100
109
  smilies: nil,
101
110
  },
102
- sidebar: [ :pages, :languages ]
111
+ sidebar: [ :pages, :languages ],
103
112
  },
104
113
 
105
114
  assets: {
@@ -108,6 +117,7 @@ module Alula
108
117
  gzip: true,
109
118
  },
110
119
  },
120
+ gzip_types: [ "js", "css", "xml", "html", "ttf", "svg", "eot" ],
111
121
 
112
122
  # Attachement Processors
113
123
  attachments: {
@@ -109,6 +109,10 @@ module Alula
109
109
  read_payload if has_payload?
110
110
  end
111
111
 
112
+ def inspect
113
+ "#<#{self.class.to_s} name=#{self.name}>"
114
+ end
115
+
112
116
  # Functionality, existence
113
117
  def exists?
114
118
  @item.exists?
@@ -181,7 +185,11 @@ module Alula
181
185
 
182
186
  # Write content to file
183
187
  @site.storage.output_public(self.path(locale)) do
184
- self.site.compressors.html.compress(output)
188
+ if self.site.compressors.html.compresses?(self)
189
+ self.site.compressors.html.compress(self, output)
190
+ else
191
+ output
192
+ end
185
193
  end
186
194
  ensure
187
195
  self.current_locale = _old_locale
@@ -237,9 +245,11 @@ module Alula
237
245
  when :languages
238
246
  # Get index page titles
239
247
  index_page = site.content.by_slug("index")
240
- index_page.languages
241
- .reject{|lang| lang == locale}
242
- .collect{|lang| Hashie::Mash.new({url: index_page.url(lang), title: I18n.t('language_name', locale: lang)}) }
248
+ if index_page
249
+ index_page.languages
250
+ .reject{|lang| lang == locale}
251
+ .collect{|lang| Hashie::Mash.new({url: index_page.url(lang), title: I18n.t('language_name', locale: lang)}) }
252
+ end
243
253
  when Hash
244
254
  item
245
255
  else
@@ -257,9 +267,10 @@ module Alula
257
267
  @metadata.permalink(locale)
258
268
  else
259
269
  template = @metadata.template || (self.class.to_s == "Alula::Content::Page" ? @site.config.pagelinks : @site.config.permalinks)
260
- self.substitutes(locale).inject(template) { |result, token|
261
- result.gsub(/:#{Regexp.escape token.first}/, token.last)
262
- }.gsub(/\/\//, '/')
270
+ substitude(template, locale)
271
+ # self.substitutes(locale).inject(template) { |result, token|
272
+ # result.gsub(/:#{Regexp.escape token.first}/, token.last)
273
+ # }.gsub(/\/\//, '/')
263
274
  end
264
275
  # Add .html only if we don't have extension already
265
276
  if ::File.extname(url).empty?
@@ -325,9 +336,14 @@ module Alula
325
336
  end
326
337
 
327
338
  # Substitues for URL
339
+ def substitude(template, locale = nil)
340
+ self.substitutes(locale).inject(template) { |result, token|
341
+ result.gsub(/:#{Regexp.escape token.first}/, token.last)
342
+ }.gsub(/\/\//, '/')
343
+ end
344
+
328
345
  def substitutes(locale = nil)
329
346
  locale ||= self.current_locale || self.site.config.locale
330
-
331
347
  @substitutes[locale] ||= begin
332
348
  subs = {
333
349
  "year" => @metadata.date.strftime('%Y'),
@@ -1,21 +1,28 @@
1
1
  module Alula
2
2
  class Generator
3
- autoload :Paginate, 'alula/generators/paginate'
4
- autoload :FeedBuilder, 'alula/generators/feedbuilder'
5
- autoload :Sitemap, 'alula/generators/sitemap'
3
+ # autoload :Paginate, 'alula/generators/paginate'
4
+ # autoload :FeedBuilder, 'alula/generators/feedbuilder'
5
+ # autoload :Sitemap, 'alula/generators/sitemap'
6
+ def self.register(name, klass); generators[name.to_s] = klass; end
7
+ def self.generators; @@generators ||= {}; end
8
+ def generators; self.class.generators; end
6
9
 
7
10
  attr_reader :options
8
11
  attr_reader :site
9
12
 
10
13
  def self.load(opts)
11
- type = opts.delete(:type)
14
+ name = opts.delete(:type).to_s
12
15
  options = opts.delete(:options)
13
16
 
14
17
  # Try to find our generator
15
- cls_name = self.constants.select {|t| t.to_s.downcase == type.downcase}.first
16
- if cls_name
17
- cls = self.const_get(cls_name)
18
- gen = cls.new(options, opts)
18
+ # cls_name = self.constants.select {|t| t.to_s.downcase == type.downcase}.first
19
+ # if cls_name
20
+ # cls = self.const_get(cls_name)
21
+ # gen = cls.new(options, opts)
22
+ # end
23
+ if generators[name] and !(!!options == options and !options)
24
+ generator = generators[name]
25
+ return generator.new(options, opts)
19
26
  end
20
27
  end
21
28
 
@@ -27,5 +34,12 @@ module Alula
27
34
  def substitutes(locale, item)
28
35
  {}
29
36
  end
37
+
38
+ def allow_compressing?
39
+ :high
40
+ end
30
41
  end
31
42
  end
43
+
44
+ # Load all generators
45
+ Dir[File.join(File.dirname(__FILE__), "generators", "*.rb")].each {|f| require f}
@@ -0,0 +1,49 @@
1
+ module Alula
2
+ class Archive < Generator
3
+ def generate
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
12
+
13
+ titles = Hash[@languages.collect {|lang, x| [lang, I18n.t("archive.title", locale: lang)]}]
14
+
15
+ archives = {}
16
+ @languages.each do |lang, posts|
17
+ options.templates.collect do |template|
18
+ posts.collect do |post|
19
+ archives[post.substitude(template, lang)] ||= {}
20
+ archives[post.substitude(template, lang)][lang] ||= []
21
+ archives[post.substitude(template, lang)][lang] << post
22
+ end
23
+ end
24
+ end
25
+
26
+ archives.each do |name, archive|
27
+ self.site.content.pages << Alula::Content::Page.new({
28
+ generator: self,
29
+ posts: archive,
30
+ title: titles.select {|lang, title| archive.keys.include?(lang)},
31
+ name: name,
32
+ slug: name,
33
+ sidebar: false,
34
+ template: "/:locale/:name/",
35
+ site: self.site,
36
+ view: "archive"
37
+ })
38
+ end
39
+ end
40
+
41
+ def substitutes(locale, item)
42
+ {
43
+ "page" => item.metadata.pagenum.to_s,
44
+ }
45
+ end
46
+ end
47
+ end
48
+
49
+ Alula::Generator.register :archive, Alula::Archive
@@ -1,7 +1,11 @@
1
- require 'builder' # As suggested by tilt
1
+ require 'builder'
2
2
 
3
3
  module Alula
4
- class Generator::FeedBuilder < Generator
4
+ class FeedBuilder < Generator
5
+ def allow_compressing?
6
+ :normal
7
+ end
8
+
5
9
  def generate
6
10
  # Loop all languages and count posts per language
7
11
  @languages = {}
@@ -52,3 +56,5 @@ module Alula
52
56
  end
53
57
  end
54
58
  end
59
+
60
+ Alula::Generator.register :feedbuilder, Alula::FeedBuilder
@@ -1,5 +1,5 @@
1
1
  module Alula
2
- class Generator::Paginate < Generator
2
+ class Paginate < Generator
3
3
  def generate
4
4
  # Loop all languages and count posts per language
5
5
  @languages = {}
@@ -68,22 +68,7 @@ module Alula
68
68
  "page" => item.metadata.pagenum.to_s,
69
69
  }
70
70
  end
71
-
72
- # def generate_content
73
- # # Generate pagination and pages
74
- # num_posts = @site.content.posts.count
75
- # pages = (num_posts / options.items).ceil
76
- #
77
- # (0..pages).each do |pagenum|
78
- # pagename = "page#{pagenum}"
79
- #
80
- # @site.generated << Alula::Content::Page.new({
81
- # site: @site,
82
- # posts: @site.content.posts.slice(options.items * pagenum, options.items),
83
- # current_page: (pagenum + 1),
84
- # name: pagename,
85
- # })
86
- # end
87
- # end
88
71
  end
89
72
  end
73
+
74
+ Alula::Generator.register :paginate, Alula::Paginate
@@ -1,7 +1,11 @@
1
1
  require 'builder' # For Tilt
2
2
 
3
3
  module Alula
4
- class Generator::Sitemap < Generator
4
+ class Sitemap < Generator
5
+ def allow_compressing?
6
+ return :normal
7
+ end
8
+
5
9
  def generate
6
10
  urls_callback = ->(context) {
7
11
  (context.site.content.posts + context.site.content.pages)
@@ -17,7 +21,7 @@ module Alula
17
21
  }.flatten
18
22
  }
19
23
 
20
- self.site.content.pages << Alula::Content::Page.new({
24
+ @sitemap_page = Alula::Content::Page.new({
21
25
  generator: self,
22
26
  urls: urls_callback,
23
27
  title: "Sitemap",
@@ -28,6 +32,14 @@ module Alula
28
32
  site: self.site,
29
33
  layout: "sitemap",
30
34
  })
35
+ self.site.content.pages << @sitemap_page
36
+
37
+ # Add link to head
38
+ Alula::Plugin.addon(:head, ->(context) {
39
+ "<link rel=\"sitemap\" type=\"application/xml\" title=\"Sitemap\" href=\"#{context.url_for(@sitemap_page.url(context.locale))}\">"
40
+ })
31
41
  end
32
42
  end
33
- end
43
+ end
44
+
45
+ Alula::Generator.register :sitemap, Alula::Sitemap
data/lib/alula/plugin.rb CHANGED
@@ -15,6 +15,7 @@ module Alula
15
15
 
16
16
  def self.addons; @@addons ||= Hash.new {|hash, key| hash[key] = []}; end
17
17
  def self.addon(type, content_or_block); addons[type] << content_or_block; end
18
+ def self.prepend_addon(type, content_or_block); addons[type].unshift content_or_block; end
18
19
 
19
20
  def self.script_load_mode=(mode)
20
21
  @@script_load_mode = case mode
data/lib/alula/site.rb CHANGED
@@ -80,6 +80,7 @@ module Alula
80
80
 
81
81
  title: @config.title,
82
82
  author: @config.author,
83
+ description: @config.description,
83
84
  tagline: @config.tagline,
84
85
  url: @config.url,
85
86
 
@@ -134,6 +135,8 @@ module Alula
134
135
 
135
136
  # Compiles a site to static website
136
137
  def generate
138
+ banner
139
+
137
140
  # Load our plugins and filters
138
141
  load_plugins
139
142
  load_filters
@@ -150,6 +153,9 @@ module Alula
150
153
  render
151
154
 
152
155
  cleanup
156
+
157
+ compress
158
+
153
159
  # Store cached version of configuration
154
160
  cached_config = File.join(storage.path(:cache), "config.yml")
155
161
  @config.write_cache(cached_config)
@@ -167,12 +173,22 @@ module Alula
167
173
  end
168
174
 
169
175
  private
176
+ def banner
177
+ puts ""
178
+ puts "Alula #{Alula::VERSION}"
179
+ end
180
+
170
181
  def load_plugins
171
182
  config.plugins.each do |name, options|
172
183
  if plugin = Alula::Plugin.load(name, options)
173
184
  @plugins[name] = plugin
174
185
  end
175
186
  end
187
+
188
+ if @plugins
189
+ puts "Plugins: " + @plugins.collect {|name, plugin| "#{name} #{plugin.version}"}.join(" ")
190
+ end
191
+ puts ""
176
192
  end
177
193
 
178
194
  def load_filters
@@ -304,7 +320,7 @@ module Alula
304
320
  io.puts "*/"
305
321
  end
306
322
  # Add stlesheet to template
307
- Alula::Plugin.addon(:head, ->(context){ context.stylesheet_link("style") })
323
+ Alula::Plugin.prepend_addon(:head, ->(context){ context.stylesheet_link("style") })
308
324
 
309
325
  # Generate javascript
310
326
  @storage.output(:cache, "assets/script.js") do |io|
@@ -339,7 +355,7 @@ module Alula
339
355
  if asset = @environment.find_asset(logical_path)
340
356
  target = File.join(@storage.path(:assets), asset.digest_path)
341
357
  asset.write_to(target)
342
- asset.write_to("#{target}.gz") if target =~ /\.(css|js)$/ and self.config.assets.gzip
358
+ # asset.write_to("#{target}.gz") if target =~ /\.(css|js)$/ and self.config.assets.gzip
343
359
  end
344
360
 
345
361
  progress.step :assets
@@ -402,7 +418,7 @@ module Alula
402
418
  assets = @environment.used.collect do |asset_name|
403
419
  if asset = @environment[asset_name]
404
420
  filename = File.join(asset_path, asset.digest_path)
405
- [filename, self.config.assets.gzip ? "#{filename}.gz" : ""]
421
+ # [filename, self.config.assets.gzip ? "#{filename}.gz" : ""]
406
422
  end
407
423
  end.flatten.reject { |u| u.nil? or !File.exists?(u) }
408
424
  outputted = @storage.outputted.reject{|o|o[/^#{asset_path}/]}
@@ -420,6 +436,22 @@ module Alula
420
436
  FileUtils.rmdir entry if Dir[File.join(entry, "**", "*")].count == 0
421
437
  end
422
438
  end
439
+
440
+ def compress
441
+ return unless config.assets.gzip
442
+
443
+ say "==> Compressing content"
444
+ Dir[File.join(@storage.path(:public), "**", "*")].each do |entry|
445
+ next unless config.gzip_types.include?(File.extname(entry)[1..-1])
446
+
447
+ gz = Zlib::GzipWriter.open("#{entry}.gz", Zlib::BEST_COMPRESSION) do |gz|
448
+ gz.write File.read(entry)
449
+ end
450
+
451
+ @storage.outputted << "#{entry}.gz"
452
+ end
453
+ end
454
+
423
455
 
424
456
  # Output helpers
425
457
  def say(msg)
data/locales/en.yml CHANGED
@@ -6,4 +6,6 @@ en:
6
6
  newer_posts: Newer
7
7
  post:
8
8
  previous: Previous Post
9
- next: Next Post
9
+ next: Next Post
10
+ archive:
11
+ title: Archive
data/locales/fi.yml CHANGED
@@ -7,4 +7,5 @@ fi:
7
7
  post:
8
8
  previous: Edellinen kirjoitus
9
9
  next: Seuraava kirjoitus
10
-
10
+ archive:
11
+ title: Arkisto
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.6
4
+ version: 0.4.7
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-07-19 00:00:00.000000000 Z
12
+ date: 2012-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parallel
@@ -486,6 +486,7 @@ files:
486
486
  - lib/alula/core_ext/tags/locale.rb
487
487
  - lib/alula/core_ext/tags/video.rb
488
488
  - lib/alula/generator.rb
489
+ - lib/alula/generators/archive.rb
489
490
  - lib/alula/generators/feedbuilder.rb
490
491
  - lib/alula/generators/paginate.rb
491
492
  - lib/alula/generators/sitemap.rb
@@ -643,7 +644,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
643
644
  version: '0'
644
645
  segments:
645
646
  - 0
646
- hash: -1337494601730845437
647
+ hash: -343637892775582502
647
648
  required_rubygems_version: !ruby/object:Gem::Requirement
648
649
  none: false
649
650
  requirements:
@@ -652,7 +653,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
652
653
  version: '0'
653
654
  segments:
654
655
  - 0
655
- hash: -1337494601730845437
656
+ hash: -343637892775582502
656
657
  requirements: []
657
658
  rubyforge_project:
658
659
  rubygems_version: 1.8.23