alula 0.2.3 → 0.4.0b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +7 -0
  3. data/Guardfile +9 -0
  4. data/Rakefile +12 -1
  5. data/VERSION +1 -1
  6. data/alula.gemspec +20 -4
  7. data/lib/alula/attachment_processor.rb +77 -0
  8. data/lib/alula/cdn.rb +30 -0
  9. data/lib/alula/cdns/edgecast.rb +16 -0
  10. data/lib/alula/cdns/hosts.rb +14 -0
  11. data/lib/alula/cli.rb +90 -39
  12. data/lib/alula/compressors.rb +22 -10
  13. data/lib/alula/config.rb +141 -0
  14. data/lib/alula/content.rb +113 -0
  15. data/lib/alula/contents/attachment.rb +8 -0
  16. data/lib/alula/contents/item.rb +409 -0
  17. data/lib/alula/contents/metadata.rb +73 -0
  18. data/lib/alula/contents/page.rb +9 -0
  19. data/lib/alula/contents/post.rb +32 -0
  20. data/lib/alula/context.rb +72 -0
  21. data/lib/alula/core_ext.rb +5 -0
  22. data/lib/alula/core_ext/environment.rb +20 -0
  23. data/lib/alula/core_ext/filter.rb +20 -0
  24. data/lib/alula/core_ext/filters/smilies.rb +36 -0
  25. data/lib/alula/core_ext/manifest.rb +30 -0
  26. data/lib/alula/core_ext/tag.rb +100 -0
  27. data/lib/alula/core_ext/tags/attachment.rb +28 -0
  28. data/lib/alula/core_ext/tags/blockquote.rb +21 -0
  29. data/lib/alula/core_ext/tags/image.rb +48 -0
  30. data/lib/alula/core_ext/tags/locale.rb +17 -0
  31. data/lib/alula/core_ext/tags/video.rb +103 -0
  32. data/lib/alula/generator.rb +31 -0
  33. data/lib/alula/generators/feedbuilder.rb +44 -0
  34. data/lib/alula/generators/paginate.rb +88 -0
  35. data/lib/alula/generators/sitemap.rb +26 -0
  36. data/lib/alula/helpers.rb +2 -0
  37. data/lib/alula/helpers/addons.rb +12 -0
  38. data/lib/alula/helpers/assets.rb +56 -0
  39. data/lib/alula/helpers/url_helpers.rb +16 -0
  40. data/lib/alula/plugin.rb +32 -0
  41. data/lib/alula/processor.rb +86 -0
  42. data/lib/alula/processors/dummy.rb +24 -0
  43. data/lib/alula/processors/image.rb +52 -0
  44. data/lib/alula/processors/magick.rb +83 -0
  45. data/lib/alula/processors/video.rb +97 -0
  46. data/lib/alula/processors/zencoder.rb +199 -0
  47. data/lib/alula/progress.rb +95 -0
  48. data/lib/alula/progressbar.rb +66 -0
  49. data/lib/alula/site.rb +331 -262
  50. data/lib/alula/storage.rb +46 -0
  51. data/lib/alula/storages/file_item.rb +43 -0
  52. data/lib/alula/storages/filestorage.rb +96 -0
  53. data/lib/alula/storages/item.rb +12 -0
  54. data/lib/alula/support/commonlogger.rb +30 -0
  55. data/lib/alula/theme.rb +70 -13
  56. data/lib/alula/theme/layout.rb +56 -0
  57. data/lib/alula/theme/view.rb +43 -0
  58. data/lib/alula/version.rb +1 -1
  59. data/locales/en.yml +9 -0
  60. data/locales/fi.yml +10 -0
  61. data/locales/l10n/ar.yml +199 -0
  62. data/locales/l10n/az.yml +199 -0
  63. data/locales/l10n/bg.yml +199 -0
  64. data/locales/l10n/bn-IN.yml +182 -0
  65. data/locales/l10n/bs.yml +242 -0
  66. data/locales/l10n/ca.yml +199 -0
  67. data/locales/l10n/cs.yml +198 -0
  68. data/locales/l10n/csb.yml +210 -0
  69. data/locales/l10n/cy.yml +199 -0
  70. data/locales/l10n/da.yml +199 -0
  71. data/locales/l10n/de-AT.yml +203 -0
  72. data/locales/l10n/de-CH.yml +203 -0
  73. data/locales/l10n/de.yml +203 -0
  74. data/locales/l10n/dsb.yml +215 -0
  75. data/locales/l10n/el.yml +199 -0
  76. data/locales/l10n/en-AU.yml +205 -0
  77. data/locales/l10n/en-CA.yml +214 -0
  78. data/locales/l10n/en-GB.yml +205 -0
  79. data/locales/l10n/en-IN.yml +205 -0
  80. data/locales/l10n/en-US.yml +205 -0
  81. data/locales/l10n/en.yml +205 -0
  82. data/locales/l10n/eo.yml +201 -0
  83. data/locales/l10n/es-AR.yml +205 -0
  84. data/locales/l10n/es-CL.yml +199 -0
  85. data/locales/l10n/es-CO.yml +205 -0
  86. data/locales/l10n/es-MX.yml +205 -0
  87. data/locales/l10n/es-PE.yml +181 -0
  88. data/locales/l10n/es-VE.yml +205 -0
  89. data/locales/l10n/es.yml +199 -0
  90. data/locales/l10n/et.yml +199 -0
  91. data/locales/l10n/eu.yml +199 -0
  92. data/locales/l10n/fa.yml +199 -0
  93. data/locales/l10n/fi.yml +199 -0
  94. data/locales/l10n/fr-CA.yml +207 -0
  95. data/locales/l10n/fr-CH.yml +207 -0
  96. data/locales/l10n/fr.yml +222 -0
  97. data/locales/l10n/fur.yml +199 -0
  98. data/locales/l10n/gl-ES.yml +178 -0
  99. data/locales/l10n/gsw-CH.yml +199 -0
  100. data/locales/l10n/he.yml +201 -0
  101. data/locales/l10n/hi-IN.yml +199 -0
  102. data/locales/l10n/hi.yml +199 -0
  103. data/locales/l10n/hr.yml +237 -0
  104. data/locales/l10n/hsb.yml +214 -0
  105. data/locales/l10n/hu.yml +199 -0
  106. data/locales/l10n/id.yml +200 -0
  107. data/locales/l10n/is.yml +213 -0
  108. data/locales/l10n/it.yml +205 -0
  109. data/locales/l10n/ja.yml +197 -0
  110. data/locales/l10n/kn.yml +199 -0
  111. data/locales/l10n/ko.yml +197 -0
  112. data/locales/l10n/lo.yml +186 -0
  113. data/locales/l10n/lt.yml +182 -0
  114. data/locales/l10n/lv.yml +215 -0
  115. data/locales/l10n/mk.yml +170 -0
  116. data/locales/l10n/mn.yml +205 -0
  117. data/locales/l10n/nb.yml +207 -0
  118. data/locales/l10n/nl.yml +199 -0
  119. data/locales/l10n/nn.yml +160 -0
  120. data/locales/l10n/pl.yml +221 -0
  121. data/locales/l10n/pt-BR.yml +207 -0
  122. data/locales/l10n/pt-PT.yml +207 -0
  123. data/locales/l10n/quotes.yml +24 -0
  124. data/locales/l10n/rm.yml +182 -0
  125. data/locales/l10n/ro.yml +199 -0
  126. data/locales/l10n/ru.yml +257 -0
  127. data/locales/l10n/sk.yml +213 -0
  128. data/locales/l10n/sl.yml +210 -0
  129. data/locales/l10n/sr-Latn.yml +170 -0
  130. data/locales/l10n/sr.yml +170 -0
  131. data/locales/l10n/sv-SE.yml +199 -0
  132. data/locales/l10n/sw.yml +197 -0
  133. data/locales/l10n/th.yml +173 -0
  134. data/locales/l10n/tl.yml +229 -0
  135. data/locales/l10n/tr.yml +199 -0
  136. data/locales/l10n/uk.yml +257 -0
  137. data/locales/l10n/vi.yml +201 -0
  138. data/locales/l10n/wo.yml +205 -0
  139. data/locales/l10n/zh-CN.yml +199 -0
  140. data/locales/l10n/zh-TW.yml +199 -0
  141. data/template/Gemfile.erb +14 -4
  142. data/template/README +16 -0
  143. data/template/config.yml.erb +42 -38
  144. data/test/fixtures/config_001_simple.yml +2 -0
  145. data/test/fixtures/config_002_l10n.yml +5 -0
  146. data/test/fixtures/pages/invalid-page.markdown +1 -0
  147. data/test/fixtures/pages/multilingual-page.markdown +20 -0
  148. data/test/fixtures/pages/section/subpage.markdown +5 -0
  149. data/test/fixtures/pages/simple-page.markdown +7 -0
  150. data/test/fixtures/posts/2012-07-02-invalid-post.markdown +1 -0
  151. data/test/fixtures/posts/2012-07-02-simple.markdown +7 -0
  152. data/test/fixtures/posts/2012-07-03-full-metadata.markdown +8 -0
  153. data/test/fixtures/posts/2012-07-03-multilingual-full-metadata.markdown +20 -0
  154. data/test/fixtures/theme/test/layouts/default.html.erb +1 -0
  155. data/test/fixtures/theme/test/views/page.html.erb +1 -0
  156. data/test/fixtures/theme/test/views/post.html.erb +1 -0
  157. data/test/minitest_helper.rb +14 -0
  158. data/test/test_config.rb +33 -0
  159. data/test/test_content.rb +30 -0
  160. data/test/test_metadata.rb +83 -0
  161. data/test/test_page.rb +81 -0
  162. data/test/test_post.rb +123 -0
  163. data/test/test_storage.rb +23 -0
  164. data/test/test_storage_file.rb +32 -0
  165. data/test/test_theme.rb +45 -0
  166. data/vendor/assets/images/favicon.png +0 -0
  167. data/vendor/assets/images/grey.gif +0 -0
  168. data/vendor/assets/javascripts/jquery.alula.js.coffee +16 -0
  169. data/vendor/{javascripts → assets/javascripts}/jquery.js +0 -0
  170. data/vendor/assets/javascripts/jquery.lazyload.js +210 -0
  171. data/vendor/assets/javascripts/lazyload.js.coffee +15 -0
  172. data/vendor/layouts/feed.xml.builder +19 -0
  173. data/vendor/layouts/sitemap.xml.builder +10 -0
  174. data/vendor/views/feed_post.html.haml +1 -0
  175. metadata +529 -50
  176. data/lib/alula.rb +0 -5
  177. data/lib/alula/assethelper.rb +0 -75
  178. data/lib/alula/plugins.rb +0 -23
  179. data/lib/alula/plugins/assets.rb +0 -82
  180. data/lib/alula/plugins/pagination.rb +0 -121
  181. data/lib/alula/rake_tasks.rb +0 -42
  182. data/lib/alula/tasks.rb +0 -2
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ .DS_Store
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in alula.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'coolline'
8
+ gem 'guard'
9
+ gem 'guard-minitest'
10
+ gem 'pry'
11
+ end
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'minitest' do
5
+ # with Minitest::Unit
6
+ watch(%r|^test/(.*)\/?test_(.*)\.rb|)
7
+ watch(%r|^lib/(.*)([^/]+)\.rb|)
8
+ watch(%r|^test/test_helper\.rb|)
9
+ end
data/Rakefile CHANGED
@@ -1,6 +1,17 @@
1
1
  #!/usr/bin/env rake
2
+ require "bundler/setup"
2
3
  require "bundler/gem_tasks"
3
4
 
4
5
  # Versioning
5
6
  require 'rake/version_task'
6
- Rake::VersionTask.new
7
+ Rake::VersionTask.new
8
+
9
+ # Tests
10
+ require "rake/testtask"
11
+
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << "test"
14
+ t.pattern = "test/**/test_*.rb"
15
+ end
16
+
17
+ task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.4.0b
@@ -16,17 +16,33 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = Alula::VERSION
18
18
 
19
- gem.add_dependency 'jekyll', '~> 0.11'
19
+ gem.add_dependency 'parallel'
20
+ gem.add_dependency 'hashie', '~> 1.2'
21
+ gem.add_dependency 'thin'
22
+ gem.add_dependency 'tilt'
23
+ gem.add_dependency 'liquid'
24
+ gem.add_dependency 'builder'
25
+ gem.add_dependency 'kramdown'
20
26
  gem.add_dependency 'sprockets', '~> 2.4'
21
27
  gem.add_dependency 'thor', '~> 0.14'
28
+ gem.add_dependency 'i18n'
22
29
  gem.add_dependency 'rmagick', '~> 2.13'
23
30
  gem.add_dependency 'sass', '~> 3.1'
24
31
  gem.add_dependency 'coffee-script', '~> 2.2'
25
32
  gem.add_dependency 'uglifier', '~> 1.2'
26
- gem.add_dependency 'front-compiler', '~> 1.1'
27
- gem.add_dependency 'activesupport', '~> 3.2'
33
+ gem.add_dependency 'htmlcompressor'
28
34
  gem.add_dependency 'stringex', '~> 1.3'
29
- gem.add_dependency 'ruby-progressbar', '~> 0.0.10'
35
+ gem.add_dependency 'powerbar'
36
+ gem.add_dependency 'mimemagic'
37
+ gem.add_dependency 'aws-sdk'
38
+ gem.add_dependency 'zencoder'
39
+ gem.add_dependency 'mini_exiftool', '~> 1.3'
40
+ gem.add_dependency 'dimensions'
41
+ gem.add_dependency 'htmlentities'
30
42
 
31
43
  gem.add_development_dependency 'version', '~> 1.0'
44
+ gem.add_development_dependency 'minitest'
45
+ gem.add_development_dependency 'turn'
46
+ gem.add_development_dependency 'simplecov'
47
+
32
48
  end
@@ -0,0 +1,77 @@
1
+ module Alula
2
+ class AttachmentProcessor
3
+ def self.register(name, klass); processors[name] = klass; end
4
+ def self.processors; @@processors ||= {}; end
5
+ def processors; self.class.processors; end
6
+
7
+ attr_reader :site
8
+
9
+ def initialize(opts)
10
+ @site = opts.delete(:site)
11
+
12
+ @@lock = Mutex.new
13
+ end
14
+
15
+ def mapping
16
+ @mapping ||= {}
17
+ end
18
+
19
+ def asset_name(name, *path)
20
+ path ||= []
21
+
22
+ @@lock.synchronize do
23
+ md5 = Digest::MD5.hexdigest(name)
24
+ asset_hash = md5[0..3]
25
+ until !mapping.key(asset_hash) or mapping.key(asset_hash) == name
26
+ asset_hash = md5[0..(asset_hash.length + 1)]
27
+ end
28
+
29
+ mapping[name] = File.join(path + [asset_hash]) + File.extname(name)
30
+ end
31
+
32
+ mapping[name]
33
+ end
34
+
35
+ def get(item)
36
+ # Try to use cached processor for extension
37
+ type = _type(item)
38
+ options = site.config.attachments[type]
39
+ self.processors[type].new(item, options: options, site: site, attachments: self)
40
+ end
41
+
42
+ private
43
+ def cached
44
+ @cached ||= {}
45
+ end
46
+
47
+ def _type(item)
48
+ if cached[item.extension] and self.processors[cached[item.extension]].process?(item, fast: true)
49
+ return cached[item.extension]
50
+ end
51
+
52
+ types = available.collect { |t| [t, false] } + available.collect { |t| [t, true] }
53
+ types.each do |type, fast|
54
+ processor = self.processors[type]
55
+ if processor.process?(item, fast: fast)
56
+ cached[item.extension] = type
57
+ return type
58
+ end
59
+ end
60
+
61
+ return "dummy"
62
+ end
63
+
64
+ def available
65
+ @@lock.synchronize do
66
+ @available ||= begin
67
+ self.site.config.attachments.processors.select { |p|
68
+ options = self.site.config.attachments[p] || {}
69
+ self.processors.has_key?(p) and self.processors[p].available?(options)
70
+ }
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ require 'alula/processor'
@@ -0,0 +1,30 @@
1
+ module Alula
2
+ class CDN
3
+ def self.register(name, klass); cdns[name.to_s] = klass; end
4
+ def self.cdns; @@cdns ||= {}; end
5
+ def cdns; self.class.cdns; end
6
+
7
+ def self.load(opts)
8
+ site = opts[:site]
9
+
10
+ # Check if we have environment related
11
+ site.config.cdn.reverse_each do |cdn, opts|
12
+ if cdns.has_key?(cdn)
13
+ return cdns[cdn].new(opts, site: site)
14
+ end
15
+ end
16
+
17
+ raise "Cannot find CDN Provider(s): #{site.config.cdn.keys}"
18
+ end
19
+
20
+ attr_reader :site
21
+ attr_reader :options
22
+
23
+ def initialize(options, opts)
24
+ @site = opts.delete(:site)
25
+ @options = options
26
+ end
27
+ end
28
+ end
29
+
30
+ Dir[File.join(File.dirname(__FILE__), "cdns", "*.rb")].each {|f| require f}
@@ -0,0 +1,16 @@
1
+ module Alula
2
+ class Edgecast < CDN
3
+ THRESHOLD = 300 * 1024 # 300kB
4
+
5
+ def url_for(name, opts)
6
+ file = opts.delete(:file)
7
+
8
+ hosts = File.size(file) < THRESHOLD ? self.options.small : self.options.large
9
+
10
+ host = hosts[Digest::MD5.hexdigest(name).to_i(16) % hosts.count]
11
+ File.join(host, name)
12
+ end
13
+ end
14
+ end
15
+
16
+ Alula::CDN.register :edgecast, Alula::Edgecast
@@ -0,0 +1,14 @@
1
+ module Alula
2
+ class Hosts < CDN
3
+ def url_for(name, opts)
4
+ if self.options[0] == "/"
5
+ File.join("/", name)
6
+ else
7
+ host = self.options[Digest::MD5.hexdigest(name).to_i(16) % self.options.count]
8
+ File.join(host, name)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ Alula::CDN.register :hosts, Alula::Hosts
@@ -1,61 +1,112 @@
1
1
  require 'thor'
2
2
  require 'alula/site'
3
+ if File.exists?("Gemfile")
4
+ require 'bundler'
5
+ Bundler.require
6
+ end
3
7
 
4
8
  module Alula
5
9
  class CLI < Thor
6
10
  include Thor::Actions
7
11
 
8
- source_root File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. template]))
12
+ TEMPLATE_DIR = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. template]))
13
+ source_root TEMPLATE_DIR
9
14
 
15
+ def self.generate_options
16
+ # option :development, :type => :boolean, :default => true,
17
+ # :desc => "Generate site using development settings. Keeps all assets and HTML uncompressed."
18
+ # option :production, :type => :boolean, :default => false,
19
+ # :desc => "Generate site using production settings. Compresses all assets and HTML."
20
+ option :environment, :type => :string, :default => 'development', :aliases => "-e",
21
+ :desc => "Environment where site is built"
22
+ option :verbose, :type => :boolean, :default => false, :aliases => "-v",
23
+ :desc => "Be verbose during site generation."
24
+ option :test, :type => :boolean, :default => false, :aliases => "-t",
25
+ :desc => "Turn on some testing features, i.e. doesn't upload/convert all files etc."
26
+ option :debug, :type => :boolean, :default => false, :aliases => "-d"
27
+ end
10
28
 
11
- desc "init [PATH]", "Creates a new aLula blog in given path or current directory"
12
- def init(path = ".")
13
- # Create directory structure
14
- %w{attachments attachments/originals attachments/_generated/images attachments/_generated/_thumbnails posts pages}.each do |dir|
15
- empty_directory File.join(path, dir)
16
- end
29
+ desc "version", "Displays current version information about loaded components"
30
+ def version
31
+ Alula::Version.print
32
+ end
33
+
34
+ desc "new [PATH]", "Creates a new empty blog"
35
+ option :edge, :type => :boolean, :default => false, :desc => "Use edge version from GIT"
36
+ option :path, :type => :string, :desc => "Use given path as alula source"
37
+ def new(path = ".")
38
+ puts "Create blog at #{path}"
17
39
 
18
- # Insert templates
19
- %w{Gemfile config.yml}.each do |tpl|
20
- template "#{tpl}.erb", File.join(path, tpl)
40
+ # Init directories
41
+ %w{content
42
+ content/attachments content/pages content/posts content/static
43
+ custom
44
+ custom/images custom/javascripts custom/stylesheets}.each do |dir|
45
+ empty_directory File.join(path, dir)
46
+ create_file File.join(path, dir, ".gitkeep")
21
47
  end
22
-
23
- # Initialize system
24
- inside File.join(path) do
25
- run "bundle install"
48
+ Dir[File.join(TEMPLATE_DIR, "**/*")].each do |tpl|
49
+ name = tpl.gsub("#{TEMPLATE_DIR}/", '')
50
+ if tpl[/\.erb$/]
51
+ template tpl, File.join(path, name.gsub(/\.erb$/, ''))
52
+ else
53
+ copy_file tpl, File.join(path, name)
54
+ end
26
55
  end
27
56
  end
28
57
 
29
58
  desc "generate", "Generates blog"
30
- method_option :development, :type => :boolean, :default => true,
31
- :desc => "Generate site using development settings. Keeps all assets and HTML uncompressed."
32
- method_option :production, :type => :boolean, :default => false,
33
- :desc => "Generate site using production settings. Compresses all assets and HTML."
34
- def generate
35
- site = Alula::Site.new("asset_compress" => (!options["development"] or options["production"]))
59
+ generate_options
60
+ def generate(*args)
61
+ unless args.empty?
62
+ args.each {|a| puts "Unknown option #{a} given."}; exit
63
+ end
36
64
  site.generate
37
65
  end
38
-
39
- desc "preview", "Preview blog"
40
- method_option :development, :type => :boolean, :default => true,
41
- :desc => "Preview site using development settings. Keeps all assets and HTML uncompressed."
42
- method_option :production, :type => :boolean, :default => false,
43
- :desc => "Preview site suing production settings. Compresses all assets and HTML."
44
- def preview
45
- site = Alula::Site.new("asset_compress" => (!options["development"] or options["production"]))
46
- site.preview
47
- end
48
66
 
49
- desc "attach POST ASSET", "Attached given asset, photo or video to given post"
50
- def attach(post, *assets)
51
- site = Alula::Site.new
52
- site.asset_attach(post, assets)
67
+ desc "preview", "Preview blog"
68
+ generate_options
69
+ option "skip-generate", :type => :boolean, :default => false, :aliases => "-s",
70
+ :desc => "Skip site generation before web server launch."
71
+ def preview(*args)
72
+ unless args.empty?
73
+ args.each {|a| puts "Unknown option #{a} given."}; exit
74
+ end
75
+ site.generate unless options['skip-generate']
76
+
77
+ # Start webserver
78
+ begin
79
+ require 'thin'
80
+ require 'alula/support/commonlogger'
81
+
82
+ public_path = site.storage.path(:public)
83
+ s = Thin::Server.start('0.0.0.0', site.config.port) do
84
+ @root = File.expand_path(public_path)
85
+ use CommonLogger
86
+ run Proc.new { |env|
87
+ path = Rack::Utils.unescape(env['PATH_INFO'])
88
+ index_file = File.join(@root, path, "index.html")
89
+
90
+ if File.exists?(index_file)
91
+ [200, {'Content-Type' => 'text/html'}, [File.read(index_file)]]
92
+ else
93
+ Rack::Directory.new(@root).call(env)
94
+ end
95
+ }
96
+ end
97
+ rescue LoadError => e
98
+ puts "Please install thin gem to use preview functionality (gem install thin)."
99
+ end
53
100
  end
54
101
 
55
- desc "clean", "Clean up all generated content"
56
- def clean
57
- site = Alula::Site.new
58
- site.clean
102
+ private
103
+ def site
104
+ @site ||= Alula::Site.new({
105
+ "environment" => options["environment"],
106
+ "verbose" => options["verbose"],
107
+ "debug" => options["debug"],
108
+ "testing" => options["test"]
109
+ })
59
110
  end
60
111
  end
61
- end
112
+ end
@@ -1,9 +1,15 @@
1
1
  require 'sass'
2
2
  require 'uglifier'
3
- require 'front-compiler'
3
+ require 'htmlcompressor'
4
4
 
5
5
  module Alula
6
- module Compressors
6
+ class Compressors
7
+ class DummyCompressor
8
+ def compress(content)
9
+ content
10
+ end
11
+ end
12
+
7
13
  class CSSCompressor
8
14
  def compress(content)
9
15
  if content.count("\n") > 2
@@ -17,19 +23,25 @@ module Alula
17
23
  end
18
24
  end
19
25
  end
20
-
26
+
21
27
  class JSCompressor
28
+ def initialize
29
+ @compressor = Uglifier.new
30
+ end
31
+
22
32
  def compress(content)
23
- @@compressor ||= Uglifier.new
24
- @@compressor.compress(content)
33
+ @compressor.compress(content)
25
34
  end
26
35
  end
27
36
 
28
- module HTMLCompressor
29
- def output_with_compression
30
- @@compressor ||= FrontCompiler.new
31
- @@compressor.compact_html(@output)
37
+ class HTMLCompressor
38
+ def initialize
39
+ @compressor = HtmlCompressor::Compressor.new
40
+ end
41
+
42
+ def compress(content)
43
+ @compressor.compress(content)
32
44
  end
33
45
  end
34
46
  end
35
- end
47
+ end
@@ -0,0 +1,141 @@
1
+ require 'hashie/mash'
2
+
3
+ module Alula
4
+ class Config
5
+ def initialize(override = {}, config_file = "config.yml")
6
+ @config = Hashie::Mash.new
7
+ @_used = Hashie::Mash.new # Keep track of applied configuration
8
+
9
+ # Load default configuration
10
+ @config.update(DEFAULT_CONFIG)
11
+
12
+ # Load project specific configuration
13
+ @config.update(YAML.load_file(config_file)) if ::File.exists?(config_file)
14
+
15
+ # Load overrides
16
+ @config.update(override)
17
+ end
18
+
19
+ def write_cache(file)
20
+ File.open(file, 'w') {|io| io.puts JSON.parse(@_used.to_json).to_yaml }
21
+ end
22
+
23
+ def method_missing(meth, *args, &blk)
24
+ if meth[/=$/]
25
+ @config.send(meth, *args)
26
+ else
27
+ value = @config.send(:[], meth)
28
+ if value.kind_of?(Hashie::Mash)
29
+ # Try environment
30
+ value = value[environment] if value.has_key?(environment)
31
+ end
32
+ @_used.send("#{meth}=", value)
33
+
34
+ value
35
+ end
36
+ end
37
+
38
+ private
39
+ DEFAULT_CONFIG = {
40
+ # The title of the blog
41
+ title: "The Unnamed Blog",
42
+ # Tagline of the blog
43
+ tagline: "This has no tagline.",
44
+ # The author, default
45
+ author: "John Doe",
46
+ # The host where blog is available
47
+ url: "http://localhost:3000",
48
+
49
+ # Base locale which is used is no other locale defined
50
+ locale: "en",
51
+ hides_base_locale: true, # Hide default locale
52
+
53
+ # Default theme
54
+ theme: 'minimal',
55
+
56
+ # Template for generating post permalinks
57
+ permalinks: '/:locale/:year/:month/:title/',
58
+ # Template for generating pages paths
59
+ pagelinks: '/:locale/:slug',
60
+
61
+ # Directories and storage
62
+ storage: {
63
+ file: {
64
+ content_path: 'content',
65
+ pages_path: 'content/pages',
66
+ posts_path: 'content/posts',
67
+ attachments_path: 'content/attachments',
68
+ static_path: 'content/static',
69
+ custom_path: 'custom',
70
+ cache_path: 'cache',
71
+ public_path: 'public',
72
+ }
73
+ },
74
+
75
+ # CDN Configuration
76
+ cdn: {
77
+ development: { hosts: ["/"] },
78
+ production: { hosts: ["/"] },
79
+ },
80
+
81
+ # Content generators
82
+ generators: {
83
+ paginate: {
84
+ items: 10,
85
+ template: "/:locale/page/:page/",
86
+ },
87
+ feedbuilder: {
88
+ items: 10,
89
+ },
90
+ sitemap: {}
91
+ },
92
+
93
+ # Plugins
94
+ plugins: {
95
+ emphasis: {},
96
+ },
97
+
98
+ # Blog Content options
99
+ content: {
100
+ filters: {
101
+ smilies: nil,
102
+ },
103
+ sidebar: [ :pages, :languages ]
104
+ },
105
+
106
+ assets: {
107
+ production: {
108
+ compress: true,
109
+ },
110
+ },
111
+
112
+ # Attachement Processors
113
+ attachments: {
114
+ "image" => {
115
+ "size" => "800x600",
116
+ "thumbnail" => "300x300",
117
+ "keep_tags" => ["CopyrightNotice", "Title", "DateTimeOriginal"],
118
+ "hires" => true,
119
+ "lazyload" => true,
120
+ },
121
+ "video" => {
122
+ "size-hd" => "1280x720",
123
+ "size-mobile-hd" => "1280x720",
124
+ "size-sd" => "640x360",
125
+ "size-mobile-sd" => "640x360",
126
+ "thumbnail" => "300x300",
127
+ "formats" => ["mp4", "webm", "ogg"],
128
+ "hires" => true,
129
+ "mobile" => true,
130
+ },
131
+ "audio" => {},
132
+
133
+ "processors" => ["magick", "zencoder"],
134
+ "magick" => {},
135
+ "zencoder" => {
136
+ "bucket" => "alula.attachments",
137
+ }
138
+ }
139
+ }
140
+ end
141
+ end