ace 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,6 @@
1
1
  = Version 0.4
2
2
  * Added project generator (ace-gen).
3
+ * Fixed filter for image thumbnails.
3
4
 
4
5
  = Version 0.3
5
6
  * Added LazyRendering mixin.
data/ace.gemspec CHANGED
@@ -11,7 +11,6 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "http://github.com/botanicus/ace"
12
12
  s.summary = "Ace is highly flexible static pages generator with template inheritance."
13
13
  s.description = "" # TODO: long description
14
- s.cert_chain = nil
15
14
  s.email = Base64.decode64("c3Rhc3RueUAxMDFpZGVhcy5jeg==\n")
16
15
  s.has_rdoc = true
17
16
 
@@ -3,37 +3,59 @@
3
3
  require "ace/filters"
4
4
  require "nokogiri"
5
5
 
6
+ # <thumbnail src="assets/img/motivation-sheet.jpg" />
7
+ # <thumbnail src="assets/img/motivation-sheet.jpg" size="550" />
8
+ # <thumbnail src="assets/img/motivation-sheet.jpg" size="550x20" />
9
+
10
+ # TODO:
11
+ # class Post < Ace::Item
12
+ # before Ace::ImageThumbnailerFilter, default_thumb_size: 550
13
+ # end
6
14
  module Ace
7
15
  class ImageThumbnailerFilter < Filter
8
- def thumb_name(filename)
9
- filename.gsub(/\.([^\.]*)$/, '_thumb.\1')
16
+ def thumb_path(file_name)
17
+ @file_name ||= file_name
18
+ @thumb_path ||= file_name.gsub(/\.([^\.]*)$/, '_thumb.\1')
19
+ end
20
+
21
+ def thumb_server_path
22
+ @thumb_path.sub("content", "")
10
23
  end
11
24
 
12
- def thumbnail_nodeset(filename, doc)
13
- a = Nokogiri::XML::Node.new 'a', doc
14
- img = Nokogiri::XML::Node.new 'img', doc
15
- a.set_attribute('href', filename)
16
- img.set_attribute('src', thumb_name(filename))
17
- img.parent = a
18
- a
25
+ def original_image_server_path
26
+ @file_name.sub("content", "")
19
27
  end
20
-
21
- def make_thumbnail_image(filename, size)
22
- size ||= 20 # default size
23
- cmd = "convert content#{filename} -resize #{size} content#{thumb_name(filename)}"
24
- warn "~ make thumbnail with '#{cmd}'"
25
- system(cmd)
26
- raise "Error when converting image 'content#{filename}'" if $?.to_i != 0
28
+
29
+ def thumbnail_nodeset(file_name, doc)
30
+ link = Nokogiri::XML::Node.new("a", doc)
31
+ image = Nokogiri::XML::Node.new("img", doc)
32
+ link.set_attribute("href", original_image_server_path)
33
+ image.set_attribute("src", thumb_server_path)
34
+ image.parent = link
35
+ return link
27
36
  end
28
37
 
29
38
  def call(item, content)
30
- puts item.inspect
39
+ puts "~ [THUMB] #{item.original_path}"
31
40
  doc = Nokogiri::HTML(content)
32
41
  doc.css("thumbnail").each do |thumb|
33
- make_thumbnail_image thumb[:src], thumb[:size]
34
- thumb.replace thumbnail_nodeset(thumb[:src], doc)
42
+ original_file = "content/#{thumb[:src]}"
43
+ generate_thumbnail(original_file, thumb[:size] || 550)
44
+ thumb.replace(thumbnail_nodeset(original_file, doc))
35
45
  end
36
46
  doc.to_s
37
47
  end
48
+
49
+ private
50
+ def generate_thumbnail(file_name, size)
51
+ unless File.exist?(thumb_path(file_name))
52
+ command = "convert #{file_name} -resize #{size} #{thumb_path(file_name)}"
53
+ warn "~ $ #{command}"
54
+ system(command)
55
+ raise "Error when converting image '#{file_name}'" if $?.to_i != 0
56
+ else
57
+ warn "~ File #{thumb_path(file_name)} already exists."
58
+ end
59
+ end
38
60
  end
39
61
  end
data/lib/ace/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Ace
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.2"
5
5
  end
@@ -18,6 +18,7 @@ source "http://gemcutter.org"
18
18
  gem "ace"
19
19
  gem "nake"
20
20
  gem "template-inheritance"
21
+ # gem "pupu"
21
22
 
22
23
  group(:development) do
23
24
  gem "rack"
@@ -8,10 +8,8 @@ Encoding.default_external = "utf-8"
8
8
  require "bundler/setup"
9
9
 
10
10
  # Custom setup.
11
- require "pupu/adapters/ace"
12
- Pupu.media_prefix = "/assets"
13
-
14
- require "helpers"
11
+ # require "pupu/adapters/ace"
12
+ # Pupu.media_prefix = "/assets"
15
13
 
16
14
  # Load the app.
17
15
  Dir["app/**/*.rb"].each do |file|
metadata CHANGED
@@ -2,14 +2,15 @@
2
2
  name: ace
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.1
5
+ version: 0.4.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain:
12
- date: 2011-06-14 00:00:00 +01:00
11
+ cert_chain: []
12
+
13
+ date: 2011-06-30 00:00:00 +02:00
13
14
  default_executable: ace
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -121,7 +122,8 @@ has_rdoc: true
121
122
  homepage: http://github.com/botanicus/ace
122
123
  licenses: []
123
124
 
124
- post_install_message: "[\e[32mVersion 0.4\e[0m] Added project generator (ace-gen).\n"
125
+ post_install_message: "[\e[32mVersion 0.4\e[0m] Added project generator (ace-gen).\n\
126
+ [\e[32mVersion 0.4\e[0m] Fixed filter for image thumbnails.\n"
125
127
  rdoc_options: []
126
128
 
127
129
  require_paths: