compass 0.13.alpha.2 → 0.13.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/Rakefile +5 -9
- data/VERSION.yml +1 -1
- data/features/command_line.feature +3 -23
- data/frameworks/compass/stylesheets/compass/_support.scss +2 -4
- data/frameworks/compass/stylesheets/compass/css3/_animation.scss +3 -10
- data/frameworks/compass/stylesheets/compass/css3/_appearance.scss +4 -5
- data/frameworks/compass/stylesheets/compass/css3/_background-clip.scss +4 -7
- data/frameworks/compass/stylesheets/compass/css3/_background-origin.scss +3 -8
- data/frameworks/compass/stylesheets/compass/css3/_background-size.scss +4 -7
- data/frameworks/compass/stylesheets/compass/css3/_border-radius.scss +4 -7
- data/frameworks/compass/stylesheets/compass/css3/_box-shadow.scss +10 -18
- data/frameworks/compass/stylesheets/compass/css3/_box-sizing.scss +4 -5
- data/frameworks/compass/stylesheets/compass/css3/_box.scss +13 -16
- data/frameworks/compass/stylesheets/compass/css3/_columns.scss +7 -8
- data/frameworks/compass/stylesheets/compass/css3/_filter.scss +4 -5
- data/frameworks/compass/stylesheets/compass/css3/_hyphenation.scss +13 -22
- data/frameworks/compass/stylesheets/compass/css3/_images.scss +39 -48
- data/frameworks/compass/stylesheets/compass/css3/_regions.scss +12 -8
- data/frameworks/compass/stylesheets/compass/css3/_shared.scss +3 -3
- data/frameworks/compass/stylesheets/compass/css3/_text-shadow.scss +21 -26
- data/frameworks/compass/stylesheets/compass/css3/_transform-legacy.scss +3 -3
- data/frameworks/compass/stylesheets/compass/css3/_transform.scss +8 -8
- data/frameworks/compass/stylesheets/compass/css3/_transition.scss +3 -3
- data/frameworks/compass/stylesheets/compass/css3/_user-interface.scss +4 -6
- data/lib/compass/commands.rb +1 -1
- data/lib/compass/commands/update_project.rb +0 -1
- data/lib/compass/configuration/data.rb +1 -1
- data/lib/compass/exec/project_options_parser.rb +13 -1
- data/lib/compass/sass_extensions/functions/cross_browser_support.rb +1 -1
- data/lib/compass/sass_extensions/functions/gradient_support.rb +68 -28
- data/lib/compass/sass_extensions/functions/sprites.rb +10 -14
- data/lib/compass/sass_extensions/functions/urls.rb +8 -4
- data/lib/compass/sass_extensions/functions/utility.rb +10 -0
- data/lib/compass/sass_extensions/sprites/engines.rb +3 -3
- data/lib/compass/sprite_importer/content.erb +2 -1
- data/lib/compass/watcher/project_watcher.rb +5 -2
- data/test/fixtures/stylesheets/compass/css/gradients.css +40 -39
- data/test/fixtures/stylesheets/compass/css/grid_background.css +7 -14
- data/test/fixtures/stylesheets/compass/css/hyphenation.css +4 -2
- data/test/fixtures/stylesheets/compass/css/pie.css +0 -1
- data/test/fixtures/stylesheets/compass/css/regions.css +4 -2
- data/test/fixtures/stylesheets/compass/css/sprites.css +2 -1
- data/test/fixtures/stylesheets/compass/css/text_shadow.css +6 -6
- data/test/fixtures/stylesheets/compass/css/vertical_rhythm.css +3 -6
- data/test/fixtures/stylesheets/compass/sass/gradients.sass +22 -0
- data/test/fixtures/stylesheets/envtest/tmp/env.css +4 -4
- data/test/helpers/diff.rb +1 -1
- data/test/integrations/sprites_test.rb +82 -48
- data/test/test_helper.rb +0 -13
- data/test/units/configuration_test.rb +12 -0
- data/test/units/regressions_test.rb +8 -8
- data/test/units/sass_extenstions/gradients_test.rb +33 -0
- data/test/units/sprites/layout_test.rb +11 -2
- data/test/units/watcher/project_watcher_test.rb +8 -0
- metadata +30 -16
- data/lib/compass/commands/generate_grid_background.rb +0 -96
- data/lib/compass/grid_builder.rb +0 -102
- data/test/units/compass_png_test.rb +0 -46
data/test/test_helper.rb
CHANGED
@@ -5,19 +5,6 @@ $:.unshift(lib_dir) unless $:.include?(lib_dir)
|
|
5
5
|
test_dir = File.dirname(__FILE__)
|
6
6
|
$:.unshift(test_dir) unless $:.include?(test_dir)
|
7
7
|
|
8
|
-
# allows testing with edge Haml by creating a test/haml symlink
|
9
|
-
linked_haml = File.dirname(__FILE__) + '/haml'
|
10
|
-
|
11
|
-
if File.exists?(linked_haml) && !$:.include?(linked_haml + '/lib')
|
12
|
-
puts "[ using linked Haml ]"
|
13
|
-
$:.unshift linked_haml + '/lib'
|
14
|
-
require 'sass'
|
15
|
-
else
|
16
|
-
need_gems = true
|
17
|
-
end
|
18
|
-
|
19
|
-
require 'rubygems' if need_gems
|
20
|
-
|
21
8
|
require 'compass'
|
22
9
|
|
23
10
|
require 'test/unit'
|
@@ -53,6 +53,18 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
53
53
|
assert_correct expected_lines, actual_lines
|
54
54
|
end
|
55
55
|
|
56
|
+
def test_custom_watch
|
57
|
+
contents = StringIO.new(<<-CONFIG)
|
58
|
+
watch 'img/**/*' do
|
59
|
+
puts 'foobar'
|
60
|
+
end
|
61
|
+
CONFIG
|
62
|
+
Compass.add_configuration(contents, 'test_watch_config')
|
63
|
+
watch = Compass.configuration.watches.first
|
64
|
+
assert_equal 'img/**/*', watch.glob
|
65
|
+
assert watch.is_a?(Compass::Watcher::Watch)
|
66
|
+
end
|
67
|
+
|
56
68
|
def test_serialization_warns_with_asset_host_set
|
57
69
|
contents = StringIO.new(<<-CONFIG)
|
58
70
|
asset_host do |path|
|
@@ -4,12 +4,16 @@ require 'compass/exec'
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
class RegressionsTest < Test::Unit::TestCase
|
7
|
+
include SpriteHelper
|
7
8
|
include Compass::CommandLineHelper
|
8
|
-
|
9
|
+
|
10
|
+
def setup
|
11
|
+
create_sprite_temp
|
9
12
|
Compass.reset_configuration!
|
10
13
|
end
|
11
14
|
|
12
|
-
|
15
|
+
def teardown
|
16
|
+
clean_up_sprites
|
13
17
|
Compass.reset_configuration!
|
14
18
|
end
|
15
19
|
|
@@ -18,12 +22,8 @@ class RegressionsTest < Test::Unit::TestCase
|
|
18
22
|
compass "create --bare issue911"
|
19
23
|
FileUtils.mkdir_p "issue911/images/sprites/a"
|
20
24
|
FileUtils.mkdir_p "issue911/images/sprites/b"
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
open "issue911/images/sprites/b/bar.png", "wb" do |f|
|
25
|
-
f.write(Compass::PNG.new(5,10, [255,255,0]).to_blob)
|
26
|
-
end
|
25
|
+
FileUtils.cp File.join(@images_tmp_path, 'nested/squares/ten-by-ten.png'), "issue911/images/sprites/a/foo.png"
|
26
|
+
FileUtils.cp File.join(@images_tmp_path, 'nested/squares/ten-by-ten.png'), "issue911/images/sprites/a/bar.png"
|
27
27
|
Dir.chdir "issue911" do
|
28
28
|
result = compile_for_project(<<-SCSS)
|
29
29
|
@import "sprites/**/*.png";
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class GradientTestClass
|
2
|
+
extend Compass::SassExtensions::Functions::Constants
|
3
|
+
extend Compass::SassExtensions::Functions::GradientSupport::Functions
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'test_helper'
|
7
|
+
require 'compass'
|
8
|
+
|
9
|
+
class GradientsTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def klass
|
12
|
+
GradientTestClass
|
13
|
+
end
|
14
|
+
|
15
|
+
def sass_string(s)
|
16
|
+
Sass::Script::String.new(s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def sass_list(array)
|
20
|
+
Sass::Script::List.new(array, :space)
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should return correct angle" do
|
24
|
+
assert_equal Sass::Script::Number.new(330, ['deg']), klass.convert_angle_from_offical(Sass::Script::Number.new(120, ['deg']))
|
25
|
+
end
|
26
|
+
|
27
|
+
test "Should convert old to new" do
|
28
|
+
[:top => ['to', 'bottom'], :bottom => ['to', 'top'], :left => ['to', 'right'], :right => ['to', 'left']].each do |test_value|
|
29
|
+
assert_equal sass_string(test_value.keys.first.to_s), klass.convert_angle_from_offical(sass_list([sass_string(test_value.values[0].first), sass_string(test_value.values[0].last)]))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -44,11 +44,11 @@ class LayoutTest < Test::Unit::TestCase
|
|
44
44
|
sprite_map_test(opts)
|
45
45
|
end
|
46
46
|
|
47
|
-
def horizontal(options= {})
|
47
|
+
def horizontal(options= {}, uri=URI)
|
48
48
|
opts = @options.merge("layout" => Sass::Script::String.new('horizontal'))
|
49
49
|
opts.merge!(options)
|
50
50
|
|
51
|
-
sprite_map_test(opts)
|
51
|
+
sprite_map_test(opts, uri)
|
52
52
|
end
|
53
53
|
|
54
54
|
# REPEAT_X
|
@@ -155,10 +155,19 @@ class LayoutTest < Test::Unit::TestCase
|
|
155
155
|
assert_equal [0, 0, 0, 0], base.images.map(&:top)
|
156
156
|
assert_equal 80, base.width
|
157
157
|
end
|
158
|
+
|
159
|
+
it "should layout horizontaly with spacing and and position" do
|
160
|
+
base = horizontal({"spacing" => Sass::Script::Number.new(10, ['px']), "position" => Sass::Script::Number.new(50, ['%'])}, 'squares/*.png')
|
161
|
+
assert_equal [0, 20], base.images.map(&:left)
|
162
|
+
assert_equal [5, 0], base.images.map(&:top)
|
163
|
+
assert_equal 50, base.width
|
164
|
+
end
|
158
165
|
|
159
166
|
it "should layout horizontaly with position" do
|
160
167
|
base = horizontal("selectors_ten_by_ten_active_position" => Sass::Script::Number.new(10, ['px']))
|
161
168
|
assert_equal [0, 10, 0, 0], base.images.map(&:top)
|
169
|
+
assert_equal 40, base.width
|
170
|
+
assert_equal 20, base.height
|
162
171
|
end
|
163
172
|
|
164
173
|
it "should generate a horrizontal sprite" do
|
@@ -15,6 +15,14 @@ class ProjectWatcherTest < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
test "should initalize correctly" do
|
17
17
|
assert @project_watcher.listener.is_a?(Listen::Listener)
|
18
|
+
assert_equal 2, @project_watcher.sass_watchers.size
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should have 3 watchers" do
|
22
|
+
Dir.chdir File.join(@working_path, 'sass') do
|
23
|
+
@project_watcher = Compass::Watcher::ProjectWatcher.new(Dir.pwd)
|
24
|
+
assert_equal 3, @project_watcher.sass_watchers.size
|
25
|
+
end
|
18
26
|
end
|
19
27
|
|
20
28
|
test "compiler" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.alpha.
|
4
|
+
version: 0.13.alpha.3
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,22 +14,27 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2013-
|
17
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: sass
|
21
|
-
requirement:
|
21
|
+
requirement: !ruby/object:Gem::Requirement
|
22
22
|
none: false
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.2.
|
26
|
+
version: 3.2.5
|
27
27
|
type: :runtime
|
28
28
|
prerelease: false
|
29
|
-
version_requirements:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.2.5
|
30
35
|
- !ruby/object:Gem::Dependency
|
31
36
|
name: chunky_png
|
32
|
-
requirement:
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
33
38
|
none: false
|
34
39
|
requirements:
|
35
40
|
- - ~>
|
@@ -37,18 +42,28 @@ dependencies:
|
|
37
42
|
version: '1.2'
|
38
43
|
type: :runtime
|
39
44
|
prerelease: false
|
40
|
-
version_requirements:
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ~>
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1.2'
|
41
51
|
- !ruby/object:Gem::Dependency
|
42
52
|
name: listen
|
43
|
-
requirement:
|
53
|
+
requirement: !ruby/object:Gem::Requirement
|
44
54
|
none: false
|
45
55
|
requirements:
|
46
|
-
- -
|
56
|
+
- - <=
|
47
57
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
58
|
+
version: 0.9.9
|
49
59
|
type: :runtime
|
50
60
|
prerelease: false
|
51
|
-
version_requirements:
|
61
|
+
version_requirements: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - <=
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.9.9
|
52
67
|
description: Compass is a Sass-based Stylesheet Framework that streamlines the creation
|
53
68
|
and maintenance of CSS.
|
54
69
|
email: chris@eppsteins.net
|
@@ -553,7 +568,6 @@ files:
|
|
553
568
|
- lib/compass/commands/create_project.rb
|
554
569
|
- lib/compass/commands/default.rb
|
555
570
|
- lib/compass/commands/extension_command.rb
|
556
|
-
- lib/compass/commands/generate_grid_background.rb
|
557
571
|
- lib/compass/commands/help.rb
|
558
572
|
- lib/compass/commands/imports.rb
|
559
573
|
- lib/compass/commands/installer_command.rb
|
@@ -593,7 +607,6 @@ files:
|
|
593
607
|
- lib/compass/exec/switch_ui.rb
|
594
608
|
- lib/compass/exec.rb
|
595
609
|
- lib/compass/frameworks.rb
|
596
|
-
- lib/compass/grid_builder.rb
|
597
610
|
- lib/compass/installers/bare_installer.rb
|
598
611
|
- lib/compass/installers/base.rb
|
599
612
|
- lib/compass/installers/manifest.rb
|
@@ -618,6 +631,7 @@ files:
|
|
618
631
|
- lib/compass/sass_extensions/functions/selectors.rb
|
619
632
|
- lib/compass/sass_extensions/functions/sprites.rb
|
620
633
|
- lib/compass/sass_extensions/functions/urls.rb
|
634
|
+
- lib/compass/sass_extensions/functions/utility.rb
|
621
635
|
- lib/compass/sass_extensions/functions.rb
|
622
636
|
- lib/compass/sass_extensions/monkey_patches/browser_support.rb
|
623
637
|
- lib/compass/sass_extensions/monkey_patches/traversal.rb
|
@@ -1066,11 +1080,11 @@ files:
|
|
1066
1080
|
- test/units/actions_test.rb
|
1067
1081
|
- test/units/command_line_test.rb
|
1068
1082
|
- test/units/compass_module_test.rb
|
1069
|
-
- test/units/compass_png_test.rb
|
1070
1083
|
- test/units/compiler_test.rb
|
1071
1084
|
- test/units/configuration_test.rb
|
1072
1085
|
- test/units/regressions_test.rb
|
1073
1086
|
- test/units/sass_extensions_test.rb
|
1087
|
+
- test/units/sass_extenstions/gradients_test.rb
|
1074
1088
|
- test/units/sprites/engine_test.rb
|
1075
1089
|
- test/units/sprites/image_row_test.rb
|
1076
1090
|
- test/units/sprites/image_test.rb
|
@@ -1107,7 +1121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1107
1121
|
version: 1.3.1
|
1108
1122
|
requirements: []
|
1109
1123
|
rubyforge_project:
|
1110
|
-
rubygems_version: 1.8.
|
1124
|
+
rubygems_version: 1.8.25
|
1111
1125
|
signing_key:
|
1112
1126
|
specification_version: 3
|
1113
1127
|
summary: A Real Stylesheet Framework
|
@@ -1526,11 +1540,11 @@ test_files:
|
|
1526
1540
|
- test/units/actions_test.rb
|
1527
1541
|
- test/units/command_line_test.rb
|
1528
1542
|
- test/units/compass_module_test.rb
|
1529
|
-
- test/units/compass_png_test.rb
|
1530
1543
|
- test/units/compiler_test.rb
|
1531
1544
|
- test/units/configuration_test.rb
|
1532
1545
|
- test/units/regressions_test.rb
|
1533
1546
|
- test/units/sass_extensions_test.rb
|
1547
|
+
- test/units/sass_extenstions/gradients_test.rb
|
1534
1548
|
- test/units/sprites/engine_test.rb
|
1535
1549
|
- test/units/sprites/image_row_test.rb
|
1536
1550
|
- test/units/sprites/image_test.rb
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'compass/commands/project_base'
|
2
|
-
require 'compass/commands/update_project'
|
3
|
-
require 'compass/grid_builder'
|
4
|
-
|
5
|
-
module Compass
|
6
|
-
module Commands
|
7
|
-
module GridBackgroundOptionsParser
|
8
|
-
def set_options(opts)
|
9
|
-
banner = %Q{Usage: compass grid-img W+GxH [path/to/grid.png]
|
10
|
-
|
11
|
-
Description:
|
12
|
-
Generates a background image that can be used to check grid alignment.
|
13
|
-
|
14
|
-
Height is optional and defaults to 20px
|
15
|
-
|
16
|
-
By default, the image generated will be named "grid.png"
|
17
|
-
and be found in the images directory.
|
18
|
-
|
19
|
-
Unless you need to check layouts in legacy browsers, it's preferable
|
20
|
-
to use the pure CSS3-based grid background mixin:
|
21
|
-
|
22
|
-
http://compass-style.org/reference/compass/layout/grid_background/
|
23
|
-
|
24
|
-
Examples:
|
25
|
-
|
26
|
-
compass grid-img 40+10 # 40px column, 10px gutter, 20px height
|
27
|
-
compass grid-img 40+20x28 # 40px column, 20px gutter, 28px height
|
28
|
-
compass grid-img 60+20x28 images/wide_grid.png
|
29
|
-
|
30
|
-
Options:
|
31
|
-
}
|
32
|
-
opts.banner = banner
|
33
|
-
|
34
|
-
super
|
35
|
-
end
|
36
|
-
end
|
37
|
-
class GenerateGridBackground < ProjectBase
|
38
|
-
|
39
|
-
include Actions
|
40
|
-
|
41
|
-
register :"grid-img"
|
42
|
-
|
43
|
-
class << self
|
44
|
-
def option_parser(arguments)
|
45
|
-
parser = Compass::Exec::CommandOptionParser.new(arguments)
|
46
|
-
parser.extend(Compass::Exec::GlobalOptionsParser)
|
47
|
-
parser.extend(GridBackgroundOptionsParser)
|
48
|
-
end
|
49
|
-
|
50
|
-
def usage
|
51
|
-
option_parser([]).to_s
|
52
|
-
end
|
53
|
-
|
54
|
-
def description(command)
|
55
|
-
"Generates a grid background image."
|
56
|
-
end
|
57
|
-
|
58
|
-
def parse!(arguments)
|
59
|
-
parser = option_parser(arguments)
|
60
|
-
parser.parse!
|
61
|
-
if arguments.size == 0
|
62
|
-
raise OptionParser::ParseError, "Please specify the grid dimensions."
|
63
|
-
end
|
64
|
-
parser.options[:grid_dimensions] = arguments.shift
|
65
|
-
parser.options[:grid_filename] = arguments.shift
|
66
|
-
parser.options
|
67
|
-
end
|
68
|
-
end
|
69
|
-
def initialize(working_path, options)
|
70
|
-
super
|
71
|
-
assert_project_directory_exists!
|
72
|
-
Compass.add_configuration(options, 'command_line')
|
73
|
-
end
|
74
|
-
|
75
|
-
def perform
|
76
|
-
unless options[:grid_dimensions] =~ /^(\d+)\+(\d+)(?:x(\d+))?$/
|
77
|
-
puts "ERROR: '#{options[:grid_dimensions]}' is not valid."
|
78
|
-
puts "Dimensions should be specified like: 30+10x20"
|
79
|
-
puts "where 30 is the column width, 10 is the gutter width, and 20 is the (optional) height."
|
80
|
-
return
|
81
|
-
end
|
82
|
-
logger.yellow do
|
83
|
-
$stderr.puts "Unless you need to check layouts in legacy browsers, it's preferable"
|
84
|
-
$stderr.puts "to use the pure CSS3-based grid background mixin:"
|
85
|
-
$stderr.puts
|
86
|
-
$stderr.puts "http://compass-style.org/reference/compass/layout/grid_background/"
|
87
|
-
end
|
88
|
-
column_width = $1.to_i
|
89
|
-
gutter_width = $2.to_i
|
90
|
-
height = $3.to_i if $3
|
91
|
-
filename = options[:grid_filename] || projectize("#{project_images_subdirectory}/grid.png")
|
92
|
-
GridBuilder.new(options.merge(:column_width => column_width, :gutter_width => gutter_width, :height => height, :filename => filename, :working_path => self.working_path)).generate!
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
data/lib/compass/grid_builder.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'zlib'
|
2
|
-
|
3
|
-
module Compass
|
4
|
-
|
5
|
-
# A simple class to represent and create a PNG-File
|
6
|
-
# No drawing features given
|
7
|
-
# Just subclass and write [R,G,B]-Byte-Values into the <tt>@data</tt> matrix
|
8
|
-
# Build for compactness, so not much error checking!
|
9
|
-
#
|
10
|
-
# Code based on seattlerb's png, see http://seattlerb.rubyforge.org/png/
|
11
|
-
class PNG
|
12
|
-
CRC_TABLE = (0..255).map do |n|
|
13
|
-
(0...8).inject(n){|x,i| x = ((x & 1) == 1) ? 0xedb88320 ^ (x >> 1) : x >> 1}
|
14
|
-
end
|
15
|
-
|
16
|
-
class << self
|
17
|
-
def crc(chunkdata='')
|
18
|
-
chunkdata.unpack('C*').inject(0xffffffff){|crc, byte| CRC_TABLE[(crc ^ byte) & 0xff] ^ (crc >> 8) } ^ 0xffffffff
|
19
|
-
end
|
20
|
-
|
21
|
-
def chunk(type, data="")
|
22
|
-
[data.size, type, data, crc(type + data)].pack("Na*a*N")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Initiates a new PNG-Object
|
27
|
-
# * <tt>width</tt>: Width of the image in pixels
|
28
|
-
# * <tt>height</tt>: Height of the image in pixels
|
29
|
-
# * <tt>background</tt>: Background-color represented as [R,G,B]-Byte-Array
|
30
|
-
def initialize(width, height, background = [255,255,255])
|
31
|
-
@height = height
|
32
|
-
@width = width
|
33
|
-
@data = Array.new(@height) { |x| Array.new(@width, background) }
|
34
|
-
end
|
35
|
-
|
36
|
-
BITS = 8
|
37
|
-
RGB = 2 # Color Types ( RGBA = 6)
|
38
|
-
NONE = 0 # Filter
|
39
|
-
|
40
|
-
# binary representation of the PNG, write to file with binary mode
|
41
|
-
def to_blob
|
42
|
-
blob = []
|
43
|
-
blob << [137, 80, 78, 71, 13, 10, 26, 10].pack("C*")
|
44
|
-
blob << PNG.chunk('IHDR', [@width, @height, BITS, RGB, NONE, NONE, NONE].pack("N2C5"))
|
45
|
-
blob << PNG.chunk('IDAT', Zlib::Deflate.deflate(self.png_join))
|
46
|
-
blob << PNG.chunk('IEND', '')
|
47
|
-
blob.join
|
48
|
-
end
|
49
|
-
|
50
|
-
def png_join
|
51
|
-
@data.map { |row| "\0" + row.map { |p| "%c%c%c" % p}.join }.join
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class GridBuilder < PNG
|
56
|
-
include Actions
|
57
|
-
|
58
|
-
attr_reader :column_width, :gutter_width, :filename, :able_to_generate, :options
|
59
|
-
|
60
|
-
# ==== Options
|
61
|
-
# * <tt>options</tt>
|
62
|
-
# * <tt>:column_width</tt> -- Width (in pixels) of current grid column
|
63
|
-
# * <tt>:gutter_width</tt> -- Width (in pixels) of current grid gutter
|
64
|
-
# * <tt>:height</tt> -- Height (in pixels) of a row
|
65
|
-
# * <tt>:filename</tt> -- Output path of grid.png file
|
66
|
-
def initialize(options={})
|
67
|
-
@column_width = options[:column_width] || 0
|
68
|
-
gutter_width = options[:gutter_width] || 0
|
69
|
-
|
70
|
-
height = options[:height] || 20
|
71
|
-
width = @column_width + gutter_width
|
72
|
-
width = 10 if width == 0
|
73
|
-
|
74
|
-
@filename = options[:filename]
|
75
|
-
@options = options
|
76
|
-
|
77
|
-
super(width, height, [0xe9,0xe9,0xe9])
|
78
|
-
end
|
79
|
-
|
80
|
-
def working_path
|
81
|
-
options[:working_path]
|
82
|
-
end
|
83
|
-
|
84
|
-
# generates (overwriting if necessary) grid.png image to be tiled in background
|
85
|
-
def generate!
|
86
|
-
(0...@height-1).each do |line|
|
87
|
-
@data[line] = Array.new(@width){|x| x < @column_width ? [0xe8, 0xef, 0xfb] : [0xff,0xff,0xff] }
|
88
|
-
end
|
89
|
-
|
90
|
-
if File.exists?(filename)
|
91
|
-
if options[:force]
|
92
|
-
overwrite = true
|
93
|
-
else
|
94
|
-
msg = "#{filename} already exists. Overwrite with --force."
|
95
|
-
raise Compass::FilesystemConflict.new(msg)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
directory File.dirname(filename)
|
99
|
-
write_file(filename, self.to_blob, options, true)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|