nutils 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Nutils Readme
2
+
3
+ A set of utilities for Nanoc3.
4
+
5
+ ## Filters
6
+
7
+ * **beautify** Retabs HTML code. Tested in Mac OS X 10.6, Ruby 1.8.7 and Nanoc 3.1.6.
8
+ * **sprockets** Runs the content through [Sprockets](http://getsprockets.org)
9
+ * **svg_to_png** Converts an SVG to PNG. Tested in Mac OS X 10.6, Ruby 1.8.7, Nanoc 3.1.6 and Batik 1.7.
10
+ * **yuicompressor** Compress the content with [YUI Compressor](http://developer.yahoo.com/yui/compressor/). Tested in Mac OS X 10.6, Ruby 1.8.7, Nanoc 3.1.6 and yui-compressor 0.9.1.
11
+
12
+ ## Data Sources
13
+ * **filesystem_customizable** Allows an array for source directories and for layout directories.
14
+
15
+ ## Contact
16
+ You can reach me at <arnau.siches@gmail.com>.
@@ -0,0 +1,40 @@
1
+ module Nutils
2
+ module DataSources
3
+
4
+ # @author Arnau Siches
5
+ #
6
+ # @version 1.0.0
7
+ #
8
+ # The +filesystem_customizable+ data source allows an array for source
9
+ # directories and for layout directories.
10
+ # Inherits from +Nanoc3::DataSources::FilesystemUnified+fromstores.
11
+ #
12
+ # @example config.yaml excerpt
13
+ # data_sources:
14
+ # -
15
+ # type: filesystem_customizable
16
+ # config:
17
+ # source_dir: ["src"]
18
+ # layout_dir: ["layouts", "other_layouts"]
19
+ #
20
+ # @see Nanoc3::DataSources::FilesystemUnified
21
+ class FilesystemCustomizable < Nanoc3::DataSources::FilesystemUnified
22
+ identifier :filesystem_customizable
23
+
24
+ def setup
25
+ # Create directories
26
+ (config[:source_dir] + config[:layout_dir]).each { |dir| FileUtils.mkdir_p dir }
27
+ end
28
+ def items
29
+ config[:source_dir].map do |dir|
30
+ load_objects(dir, 'item', Nanoc3::Item)
31
+ end.flatten
32
+ end
33
+ def layouts
34
+ config[:layout_dir].map do |dir|
35
+ load_objects(dir, 'layout', Nanoc3::Layout)
36
+ end.flatten
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ module Nutils
2
+ module DataSources
3
+ autoload "FilesystemCustomizable", "nutils/data_sources/filesystem_customizable"
4
+
5
+ ::Nanoc3::DataSource.register "::Nutils::DataSources::FilesystemCustomizable", :filesystem_customizable
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ module Nutils
2
+ module Filters
3
+
4
+ # @author Arnau Siches
5
+ # @author Choan Gálvez
6
+ #
7
+ # @version 0.5.0
8
+ #
9
+ # @note Requires htmlbeautifer
10
+ #
11
+ # @todo Pass parameters to the HtmlBeautifer engine.
12
+ class Beautify < Nanoc3::Filter
13
+
14
+ identifier :beautify
15
+ type :text
16
+
17
+ # Runs the content through [htmlbeautifier](http://github.com/threedaymonk/htmlbeautifier/).
18
+ # This method takes no options.
19
+ #
20
+ # @param [String] content The content to filter.
21
+ #
22
+ # @return [String] The retabed HTML.
23
+ def run(content, params = {})
24
+ require "htmlbeautifier/beautifier"
25
+ buffer = ""
26
+ ::HtmlBeautifier::Beautifier.new(buffer).scan(content)
27
+ buffer
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ module Nutils
2
+ module Filters
3
+
4
+ # @author Arnau Siches
5
+ #
6
+ # @version 1.0.0
7
+ #
8
+ # @note Requires «sprockets»
9
+ class SprocketWheel < Nanoc3::Filter
10
+
11
+ identifier :sprockets
12
+ type :text
13
+
14
+ # Concatenate the Javascript content through [Sprockets](http://getsprockets.org).
15
+ # This method takes no options.
16
+ #
17
+ # @param [String] content The content to filter.
18
+ #
19
+ # @return [String] The filtered content.
20
+ def run(content, params={})
21
+ require "sprockets"
22
+ require "tempfile"
23
+
24
+ tmp_file = Tempfile.new("sprockets.tmp", File.dirname(@item[:filename]))
25
+
26
+ tmp_file.puts content
27
+ tmp_file.open
28
+
29
+ source_files = tmp_file.path
30
+ load_path = params[:load_path] || File.dirname(@item[:filename])
31
+
32
+ params.merge!({
33
+ :load_path => load_path,
34
+ :source_files => [source_files]
35
+ })
36
+
37
+ secretary = ::Sprockets::Secretary.new(params)
38
+ secretary.install_assets if params[:asset_root]
39
+ secretary.concatenation
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,96 @@
1
+ module Nutils
2
+ module Filters
3
+
4
+ # @author Arnau Siches
5
+ # @author Choan Gálvez
6
+ #
7
+ # @version 0.2.0
8
+ #
9
+ # @note Requires «rjb»
10
+ class SvgToPng < Nanoc3::Filter
11
+
12
+ identifier :svg_to_png
13
+ type :text => :binary
14
+
15
+ def initialize(hash = {})
16
+ require "rjb"
17
+ require "tempfile"
18
+
19
+ Rjb::load(classpath = '.', [ '-Djava.awt.headless=true', '-Dapple.awt.graphics.UseQuartz=false' ])
20
+ @fileOutputStream = Rjb::import("java.io.FileOutputStream")
21
+ @pngTranscoder = Rjb::import("org.apache.batik.transcoder.image.PNGTranscoder")
22
+ @transcoderInput = Rjb::import("org.apache.batik.transcoder.TranscoderInput")
23
+ @transcoderOutput = Rjb::import("org.apache.batik.transcoder.TranscoderOutput")
24
+ @float = Rjb::import("java.lang.Float")
25
+ @integer = Rjb::import("java.lang.Integer")
26
+ @color = Rjb::import("java.awt.Color")
27
+ @@_initialized = true
28
+ super
29
+ end
30
+
31
+ # Runs the content through [Batik](http://xmlgraphics.apache.org/batik/).
32
+ #
33
+ # @param [String] content The content to filter.
34
+ #
35
+ # @option params [String] :background_color (nil) The background color with the
36
+ # form +#FFCC00+ or +FC0+ of the result. Mask for the
37
+ # +KEY_BACKGROUND_COLOR+ key.
38
+ #
39
+ # @option params [Integer] :dpi (72) This parameter lets you use the pixel
40
+ # to millimeter conversion factor.
41
+ # This factor is used to determine how units are converted into pixels.
42
+ # Mask for the +KEY_PIXEL_TO_MM+ key.
43
+ #
44
+ # @option params [Integer] :heigth (nil) The height of the result. Mask for the
45
+ # +KEY_HEIGHT+ key.
46
+ #
47
+ # @option params [Integer] :width (nil) The width of the result. Mask for the
48
+ # +KEY_WIDTH+ key.
49
+ #
50
+ # @return [String] The filtered content.
51
+ def run(content, params = {})
52
+ t = @pngTranscoder.new
53
+
54
+ opts = {
55
+ :background_color => nil,
56
+ :dpi => 72,
57
+ :height => nil,
58
+ :width => nil,
59
+ }.merge(params)
60
+
61
+ t.addTranscodingHint(@pngTranscoder.KEY_WIDTH, @float.new(opts[:width])) if opts[:width]
62
+ t.addTranscodingHint(@pngTranscoder.KEY_HEIGHT, @float.new(opts[:height])) if opts[:height]
63
+ t.addTranscodingHint(@pngTranscoder.KEY_PIXEL_TO_MM, @float.new(254 / opts[:dpi])) if opts[:dpi]
64
+ t.addTranscodingHint(@pngTranscoder.KEY_BACKGROUND_COLOR, @color.new(hex2int(opts[:background_color]))) if opts[:background_color]
65
+ # t.addTranscodingHint(@pngTranscoder.KEY_BACKGROUND_COLOR, @color.decode('#FC0'))
66
+
67
+ tempfile = Tempfile.new(filename.gsub(/[^a-zA-Z0-9]/, '-'), ".")
68
+ temppath = tempfile.path
69
+ tempfile.puts content
70
+ tempfile.close
71
+
72
+ uri = "file:" + File.expand_path(temppath)
73
+
74
+ input = @transcoderInput.new(uri)
75
+ ostream = @fileOutputStream.new(output_filename)
76
+ output = @transcoderOutput.new(ostream)
77
+ t.transcode(input, output)
78
+
79
+ ostream.flush()
80
+ ostream.close()
81
+ end
82
+
83
+ # Converts an hexadecimal number with the format +#FC0+ or +#FFCC00+ to its integer representation.
84
+ #
85
+ # @param [String] input The hexadecimal number.
86
+ #
87
+ # @return [Integer] The corresponding integer.
88
+ def hex2int(input)
89
+ hexnum = input.delete("#")
90
+ raise ArgumentError, "Got #{input}. Hexadecimal number must have the form #FC0 or #FFCC00." unless (hexnum.length == 3 or hexnum.length == 6)
91
+ (hexnum.length == 3) ? hexnum.map { |i| i + i }.to_s.hex : hexnum.hex
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,28 @@
1
+ module Nutils
2
+ module Filters
3
+
4
+ # @author Arnau Siches
5
+ #
6
+ # @version 1.0.0
7
+ #
8
+ # @note Requires «yui-compressor»
9
+ class YuiCompressor < Nanoc3::Filter
10
+
11
+ identifier :yuicompressor
12
+ type :text
13
+
14
+ # Compress the content with [YUI Compressor](http://developer.yahoo.com/yui/compressor/).
15
+ # This method takes no options.
16
+ #
17
+ # @param [String] content The content to filter.
18
+ #
19
+ # @return [String] The filtered content.
20
+ def run(content, params={})
21
+ require "yui/compressor"
22
+ compressor = ::YUI::JavaScriptCompressor.new(params)
23
+ compressor.compress(content)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ module Nutils
2
+ module Filters
3
+ autoload "Beautify", "nutils/filters/beautify"
4
+ autoload "Sprockets", "nutils/filters/sprockets"
5
+ autoload "Svg2Png", "nutils/filters/svg2png"
6
+ autoload "YuiCompressor", "nutils/filters/yuicompressor"
7
+
8
+ ::Nanoc3::Filter.register "::Nutils::Filters::Beautify", :beautify
9
+ ::Nanoc3::Filter.register "::Nutils::Filters::Sprockets", :sprockets
10
+ ::Nanoc3::Filter.register "::Nutils::Filters::Svg2Png", :svg2png
11
+ ::Nanoc3::Filter.register "::Nutils::Filters::YuiCompressor", :yuicompressor
12
+ end
13
+ end
data/lib/nutils.rb ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module Nutils
4
+
5
+ # The current nutils version.
6
+ VERSION = "0.5.0"
7
+
8
+ end
9
+
10
+ # Load requirements
11
+ require "nanoc3"
12
+
13
+ # Load nutils
14
+ require "nutils/data_sources"
15
+ require "nutils/filters"
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nutils
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
+ platform: ruby
12
+ authors:
13
+ - Arnau Siches
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-06 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nanoc3
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 1
33
+ - 2
34
+ version: 3.1.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rjb
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 13
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 9
50
+ version: 1.2.9
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: yui-compressor
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 57
62
+ segments:
63
+ - 0
64
+ - 9
65
+ - 1
66
+ version: 0.9.1
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: htmlbeautifier
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ type: :runtime
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: sprockets
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ type: :runtime
96
+ version_requirements: *id005
97
+ description: Nutils is a set of utilities like filters, data_sources and helpers for Nanoc3.
98
+ email: arnau.siches@gmail.com
99
+ executables: []
100
+
101
+ extensions: []
102
+
103
+ extra_rdoc_files:
104
+ - README.md
105
+ files:
106
+ - lib/nutils/data_sources/filesystem_customizable.rb
107
+ - lib/nutils/data_sources.rb
108
+ - lib/nutils/filters/beautify.rb
109
+ - lib/nutils/filters/sprockets.rb
110
+ - lib/nutils/filters/svg2png.rb
111
+ - lib/nutils/filters/yuicompressor.rb
112
+ - lib/nutils/filters.rb
113
+ - lib/nutils.rb
114
+ - README.md
115
+ has_rdoc: yard
116
+ homepage: http://github.com/arnau/Nutils/
117
+ licenses: []
118
+
119
+ post_install_message:
120
+ rdoc_options:
121
+ - --main
122
+ - README.md
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 57
131
+ segments:
132
+ - 1
133
+ - 8
134
+ - 7
135
+ version: 1.8.7
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ requirements: []
146
+
147
+ rubyforge_project:
148
+ rubygems_version: 1.3.7
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: A set of utilities for Nanoc3.
152
+ test_files: []
153
+