laysl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +14 -0
- data/README.txt +82 -0
- data/Rakefile +15 -0
- data/bin/laysl +23 -0
- data/lib/area.rb +152 -0
- data/lib/context/areas/buffer.rb +16 -0
- data/lib/context/areas/page.rb +35 -0
- data/lib/context/example.rb +63 -0
- data/lib/context/header.rb +14 -0
- data/lib/context/load.rb +13 -0
- data/lib/laysl.rb +5 -0
- data/spec/area_specs.rb +277 -0
- data/spec/page_specs.rb +52 -0
- metadata +67 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
bin/laysl
|
6
|
+
lib/laysl.rb
|
7
|
+
lib/area.rb
|
8
|
+
lib/context/example.rb
|
9
|
+
lib/context/header.rb
|
10
|
+
lib/context/load.rb
|
11
|
+
lib/context/areas/buffer.rb
|
12
|
+
lib/context/areas/page.rb
|
13
|
+
spec/area_specs.rb
|
14
|
+
spec/page_specs.rb
|
data/README.txt
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
laysl
|
2
|
+
written by evan short
|
3
|
+
funded and founded by kalin harvey and trevor lott of dealer diagnostics
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
this package makes a chain dsl for laying out a page. simple areas are
|
8
|
+
described using block syntax. extending and rendering objects is easily
|
9
|
+
overwritable, but does very little as it stands.
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
* beta
|
14
|
+
* needs more ponies
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
ok, the first time you run +laysl+ you will get a <tt>~/.laysl</tt> and that
|
19
|
+
will define a context for you. make sense? good. check out load.rb
|
20
|
+
in ~/.laysl to make it make even more sense.
|
21
|
+
|
22
|
+
the only real object in effect is the Area. everything else extends
|
23
|
+
area at the moment. in the future i will pull the dsl module out
|
24
|
+
of the area class and then you will need to include the dsl module
|
25
|
+
instead of extending the Area. all of that will change. don't worry
|
26
|
+
about it. srsly.
|
27
|
+
|
28
|
+
be sure to check out the <tt>~/.laysl/areas</tt> folder for examples on doing
|
29
|
+
stuff. like extending an area to make a page.
|
30
|
+
|
31
|
+
also you have an example file that you can look at and run. after
|
32
|
+
running +laysl+ you will have <tt>~/.laysl/</tt> and it will have
|
33
|
+
+example.rb+ and you can run that with <tt>laysl ~/.laysl/example.rb</tt>
|
34
|
+
|
35
|
+
one thing i will try to explain:
|
36
|
+
|
37
|
+
this:
|
38
|
+
@page.record_all do |area|
|
39
|
+
puts area.record.inspect
|
40
|
+
end
|
41
|
+
|
42
|
+
and this:
|
43
|
+
class Area
|
44
|
+
def render
|
45
|
+
puts record.inspect
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@page.record_all(:render)
|
50
|
+
|
51
|
+
do the same thing. im glad we workd that out.
|
52
|
+
|
53
|
+
questions can be sent to evan.short@dontspamme.gmail.seriously.dontspamme.com
|
54
|
+
|
55
|
+
== INSTALL:
|
56
|
+
|
57
|
+
sudo gem install laysl
|
58
|
+
|
59
|
+
== LICENSE:
|
60
|
+
|
61
|
+
(The MIT License)
|
62
|
+
|
63
|
+
Copyright (c) 2007 Evan Short, Kalin Harvey, Trevor Lott
|
64
|
+
|
65
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
66
|
+
a copy of this software and associated documentation files (the
|
67
|
+
'Software'), to deal in the Software without restriction, including
|
68
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
69
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
70
|
+
permit persons to whom the Software is furnished to do so, subject to
|
71
|
+
the following conditions:
|
72
|
+
|
73
|
+
The above copyright notice and this permission notice shall be
|
74
|
+
included in all copies or substantial portions of the Software.
|
75
|
+
|
76
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
77
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
78
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
79
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
80
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
81
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
82
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/laysl.rb'
|
6
|
+
|
7
|
+
Hoe.new('laysl', Laysl::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'laysl'
|
9
|
+
# p.summary = 'FIX'
|
10
|
+
# p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
11
|
+
# p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
# vim: syntax=Ruby
|
data/bin/laysl
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileUtils'
|
4
|
+
ENV['LAYSL'] ||= ENV['HOME']+'/.laysl'
|
5
|
+
|
6
|
+
#::NOTE:: THIS IS FOR TESTING
|
7
|
+
FileUtils.rm_rf ENV['LAYSL']
|
8
|
+
# comment out before gem'ing
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))+'/context')
|
11
|
+
|
12
|
+
if File.exist?(ENV['LAYSL']) && File.directory?(ENV['LAYSL'])
|
13
|
+
$LOAD_PATH.unshift(ENV['LAYSL'])
|
14
|
+
else
|
15
|
+
FileUtils.cp_r File.expand_path(File.expand_path(File.dirname(__FILE__))+'/../lib/context'), ENV['LAYSL']
|
16
|
+
$LOAD_PATH.unshift(ENV['LAYSL'])
|
17
|
+
end
|
18
|
+
|
19
|
+
require File.dirname(__FILE__)+'/../lib/laysl'
|
20
|
+
|
21
|
+
load ENV['LAYSL']+'/load.rb'
|
22
|
+
|
23
|
+
load ARGV[0] if ARGV[0]
|
data/lib/area.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
class Area
|
2
|
+
attr_accessor :coordinates
|
3
|
+
attr_accessor :size
|
4
|
+
attr_accessor :border
|
5
|
+
attr_accessor :subs
|
6
|
+
attr_accessor :record
|
7
|
+
|
8
|
+
def initialize(coords, options={}, &blk)
|
9
|
+
@size ||= {}
|
10
|
+
@border ||= {}
|
11
|
+
@subs ||= []
|
12
|
+
set_coordinates coords
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_coordinates(coords)
|
16
|
+
coords = case coords
|
17
|
+
when Array : {:x => coords[0], :y => coords[1]}
|
18
|
+
when Hash : coords
|
19
|
+
else
|
20
|
+
raise 'invalid coordinate format'
|
21
|
+
end
|
22
|
+
@coordinates = coords
|
23
|
+
if coordinates[:x] && coordinates[:y]
|
24
|
+
coordinates[:x] = coordinates[:x].to_f
|
25
|
+
coordinates[:y] = coordinates[:y].to_f
|
26
|
+
else
|
27
|
+
raise 'invalid coordinate information {:x => x, :y => y}'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def set_size which=nil
|
33
|
+
which ||= nil
|
34
|
+
@size = case which
|
35
|
+
when Symbol
|
36
|
+
sizes[which]
|
37
|
+
when Hash
|
38
|
+
which
|
39
|
+
else
|
40
|
+
raise('invalid size')
|
41
|
+
end
|
42
|
+
size || raise('no such size')
|
43
|
+
end
|
44
|
+
|
45
|
+
def sizes
|
46
|
+
{}
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_size_in opts
|
50
|
+
opts[:size] ||= {}
|
51
|
+
opts[:size][:height] = opts[:height] if opts[:height]
|
52
|
+
opts[:size][:width] = opts[:width] if opts[:width]
|
53
|
+
|
54
|
+
opts[:size][:width] = '100%' unless opts[:size][:width]
|
55
|
+
opts[:size][:height] = '100%' unless opts[:size][:height]
|
56
|
+
|
57
|
+
opts[:size].empty? ? nil : opts[:size]
|
58
|
+
end
|
59
|
+
|
60
|
+
def convert_percentages opts
|
61
|
+
opts.each { |name, value|
|
62
|
+
break unless size[name]
|
63
|
+
opts[name] = (opts[name].to_f/100.0)*size[name] if opts[name] =~ /^\d*\%$/
|
64
|
+
opts[name] = opts[name].to_f unless size[name].kind_of? String
|
65
|
+
}
|
66
|
+
opts
|
67
|
+
end
|
68
|
+
|
69
|
+
def define_size_from opts={}
|
70
|
+
opts ||= {}
|
71
|
+
opts[:size] ||= {}
|
72
|
+
opts[:size][:unit] = size[:unit]
|
73
|
+
opts[:size].merge convert_percentages(find_size_in(opts))
|
74
|
+
end
|
75
|
+
|
76
|
+
def method_name; caller[0][/`([^']*)'/, 1]; end
|
77
|
+
|
78
|
+
def generate_sub_area(options={}, &blk)
|
79
|
+
commit_sub(make_sub_area(options), options[:area], &blk)
|
80
|
+
end
|
81
|
+
|
82
|
+
def make_sub_area(options={}, &blk)
|
83
|
+
coords = next_sub_coords
|
84
|
+
options[:size] = convert_percentages(find_size_in(options))
|
85
|
+
options[:size][:unit] = size[:unit]
|
86
|
+
|
87
|
+
if options[:size][:width] > width+x - coords[0].to_f
|
88
|
+
coords = next_sub_coords :under
|
89
|
+
end
|
90
|
+
if options[:size][:width] > width+x - coords[0].to_f
|
91
|
+
raise DoNotWant, '(x too big)' unless ((width+x) - coords[1].to_f - options[:size][:width]).abs < 0.000001
|
92
|
+
end
|
93
|
+
if options[:size][:height] > ((height+y) - coords[1].to_f)
|
94
|
+
raise DoNotWant, '(y too big)' unless ((height+y) - coords[1].to_f - options[:size][:height]).abs < 0.000001
|
95
|
+
end
|
96
|
+
a = (options[:area] || Area).new(coords, options, &blk)
|
97
|
+
a.set_size options[:size]
|
98
|
+
a
|
99
|
+
end
|
100
|
+
|
101
|
+
def commit_sub area, dont_yield=false
|
102
|
+
subs << area
|
103
|
+
yield area if block_given? unless dont_yield
|
104
|
+
subs.last
|
105
|
+
end
|
106
|
+
|
107
|
+
def next_sub_coords where = nil
|
108
|
+
return(coordinates) if subs.empty?
|
109
|
+
reference = subs.last
|
110
|
+
unless where
|
111
|
+
return [reference.x+reference.width, reference.y]
|
112
|
+
else
|
113
|
+
return [reference.x, reference.y+reference.height]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def recording
|
118
|
+
@record = {:coords => [x, y],
|
119
|
+
:dimensions => [width, height],
|
120
|
+
:units => size[:unit],
|
121
|
+
:border => border}
|
122
|
+
record
|
123
|
+
end
|
124
|
+
|
125
|
+
def record_subs
|
126
|
+
@subs.each {|sub| sub.record_all}
|
127
|
+
end
|
128
|
+
|
129
|
+
def record_all method=nil, *args, &blk
|
130
|
+
recording
|
131
|
+
record_subs
|
132
|
+
each_record(method, *args, &blk) if method or block_given?
|
133
|
+
end
|
134
|
+
|
135
|
+
def each_record(method=nil, *args, &blk)
|
136
|
+
send(method, *args) if method
|
137
|
+
yield self if block_given?
|
138
|
+
@subs.each {|sub| sub.each_record(method, *args, &blk)}
|
139
|
+
end
|
140
|
+
|
141
|
+
def height; size[:height] end
|
142
|
+
def width ; size[:width] end
|
143
|
+
def x; coordinates[:x] end
|
144
|
+
def y; coordinates[:y] end
|
145
|
+
def render; end
|
146
|
+
|
147
|
+
alias area generate_sub_area
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
class DoNotWant < StandardError
|
152
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Buffer < Area
|
2
|
+
attr_accessor :text
|
3
|
+
def initialize(coords, options={})
|
4
|
+
@text = {}
|
5
|
+
super(coords, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def sizes
|
9
|
+
{:standard => {:height => 0.5, :unit => 'inches'}}
|
10
|
+
end
|
11
|
+
|
12
|
+
def record
|
13
|
+
record = super.merge({:text => text})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Page < Area
|
2
|
+
def initialize(options={})
|
3
|
+
set_size(options[:size] || :standard)
|
4
|
+
apply_orientation(options[:orient] || options[:orientation] || :landscape)
|
5
|
+
options[:size] = apply_orientation if @orientation
|
6
|
+
super([0,0], options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def apply_orientation which=nil
|
10
|
+
case which
|
11
|
+
when :portrait
|
12
|
+
size[:height] = size[:long] if size[:long]
|
13
|
+
size[:width] = size[:short] if size[:short]
|
14
|
+
when :landscape
|
15
|
+
size[:height] = size[:short] if size[:short]
|
16
|
+
size[:width] = size[:long] if size[:long]
|
17
|
+
else
|
18
|
+
raise 'orientation must be either portrait or landscape'
|
19
|
+
end
|
20
|
+
|
21
|
+
if size[:height] && size[:width]
|
22
|
+
size[:height] = size[:height].to_f
|
23
|
+
size[:width] = size[:width].to_f
|
24
|
+
else
|
25
|
+
raise 'need to set a height and width before orienting'
|
26
|
+
end
|
27
|
+
size
|
28
|
+
end
|
29
|
+
|
30
|
+
def sizes
|
31
|
+
{:standard => {:long => 11.0, :short => 8.5, :unit => 'inches'}}
|
32
|
+
end
|
33
|
+
|
34
|
+
alias content generate_sub_area
|
35
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
@area = Area.new([0,0],
|
2
|
+
{:size => {:height => 1.0,
|
3
|
+
:width => 3.0,
|
4
|
+
:unit => 'inches'}})
|
5
|
+
|
6
|
+
@graphs = [@area, @area, @area]
|
7
|
+
|
8
|
+
@page = Page.new
|
9
|
+
@page.start_columns(:height => '50%') do |s|
|
10
|
+
s.column(:width => '50%'){ |c|
|
11
|
+
c.area(:height => '50%') { |a|
|
12
|
+
a.header(:height => 0.3){ |h|
|
13
|
+
h.text[:center] = 'first block'
|
14
|
+
h.border[:bottom] = '1px'
|
15
|
+
}
|
16
|
+
#a.until_full_put(@graphs)
|
17
|
+
}
|
18
|
+
c.area(:height => '50%') { |a|
|
19
|
+
a.header(:height => 0.3){ |h|
|
20
|
+
h.text[:center] = 'second block'
|
21
|
+
h.text[:left] = Time.now.to_s
|
22
|
+
h.border[:bottom] = '1px'
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
s.column(:width => '50%'){ |c|
|
27
|
+
c.area(:height => '50%') { |a|
|
28
|
+
a.header(:height => 0.3){ |h|
|
29
|
+
h.border[:bottom] = '1px'
|
30
|
+
h.text[:left] = Time.now.to_s
|
31
|
+
}
|
32
|
+
}
|
33
|
+
c.area(:height => '50%') { |a|
|
34
|
+
a.header(:height => 0.3){ |h|
|
35
|
+
h.border[:bottom] = '1px'
|
36
|
+
h.text[:left] = Time.now.to_s
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
@page.area(:height => '50%') do |a|
|
42
|
+
a.header(:height => 0.3){ |h|
|
43
|
+
h.text[:full] = 'here is an area!'
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
@page.record_all do |area|
|
48
|
+
puts area.record.inspect
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "\n** alternatively you can do **\n"
|
52
|
+
|
53
|
+
class Area
|
54
|
+
def render
|
55
|
+
puts record.inspect
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
@page.record_all(:render)
|
60
|
+
|
61
|
+
# which will run the render method of everything under @page
|
62
|
+
# may also send args like (:method, arg1, arg2)
|
63
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Context
|
2
|
+
def header(opts, &blk)
|
3
|
+
head = generate_sub_area(opts.merge(:area => Buffer))
|
4
|
+
yield head if block_given?
|
5
|
+
head.start_columns(opts) do |a|
|
6
|
+
a.column(:width => '25%') { |b|
|
7
|
+
}
|
8
|
+
a.column(:width => '50%') { |b|
|
9
|
+
}
|
10
|
+
a.column(:width => '25%') { |b|
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/context/load.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)+'/areas')
|
3
|
+
|
4
|
+
require 'page'
|
5
|
+
require 'header'
|
6
|
+
require 'buffer'
|
7
|
+
|
8
|
+
class Area
|
9
|
+
include Context
|
10
|
+
alias column generate_sub_area
|
11
|
+
alias start_columns generate_sub_area
|
12
|
+
end
|
13
|
+
|
data/lib/laysl.rb
ADDED
data/spec/area_specs.rb
ADDED
@@ -0,0 +1,277 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../lib/area'
|
2
|
+
|
3
|
+
def start_area
|
4
|
+
@area = Area.new([0,0], {})
|
5
|
+
end
|
6
|
+
|
7
|
+
def area
|
8
|
+
@area
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'an area should' do
|
12
|
+
setup do
|
13
|
+
start_area
|
14
|
+
@area.stub!(:size).and_return(:standard)
|
15
|
+
@area.stub!(:coordinates).and_return({:x=>0, :y=>0})
|
16
|
+
@area.stub!(:border).and_return({})
|
17
|
+
end
|
18
|
+
|
19
|
+
teardown do
|
20
|
+
@area = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
specify 'have a size' do
|
24
|
+
area.size.should_be_kind_of? Hash
|
25
|
+
end
|
26
|
+
|
27
|
+
specify 'have coordinates' do
|
28
|
+
area.coordinates.should_be_kind_of Hash
|
29
|
+
end
|
30
|
+
|
31
|
+
specify 'have a border' do
|
32
|
+
area.border.should_be_kind_of Hash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'the information necessary for subs' do
|
37
|
+
setup do
|
38
|
+
start_area
|
39
|
+
@area.stub!(:size).and_return(:standard)
|
40
|
+
@area.stub!(:coordinates).and_return({:x=>0, :y=>0})
|
41
|
+
@area.stub!(:border).and_return({})
|
42
|
+
end
|
43
|
+
|
44
|
+
teardown do
|
45
|
+
@area = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
specify 'an array of subs' do
|
49
|
+
area.subs.should_respond_to :each
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'an area instantiated with an invalid size should' do
|
54
|
+
setup do
|
55
|
+
start_area
|
56
|
+
@area.stub!(:coordinates).and_return({:x=>0, :y=>0})
|
57
|
+
@area.stub!(:border).and_return({})
|
58
|
+
end
|
59
|
+
|
60
|
+
teardown do
|
61
|
+
@area = nil
|
62
|
+
end
|
63
|
+
specify 'raise an error' do
|
64
|
+
lambda{area.set_size(:no_such_size)}.should_raise
|
65
|
+
end
|
66
|
+
specify 'raise an error' do
|
67
|
+
lambda{area.set_size({})}.should_not_raise
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'the size of an area should' do
|
72
|
+
setup do
|
73
|
+
start_area
|
74
|
+
@area.stub!(:coordinates).and_return({:x=>0, :y=>0})
|
75
|
+
@area.stub!(:border).and_return({})
|
76
|
+
@area.set_size({:width => 11.0, :height => 8.5, :unit => 'inches'})
|
77
|
+
end
|
78
|
+
|
79
|
+
specify 'have a height' do
|
80
|
+
@area.size[:height].should_be_kind_of Float
|
81
|
+
end
|
82
|
+
|
83
|
+
specify 'have a width' do
|
84
|
+
@area.size[:width].should_be_kind_of Float
|
85
|
+
end
|
86
|
+
|
87
|
+
specify 'have units' do
|
88
|
+
@area.size[:unit].should_be_kind_of String
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when setting the size of an area from a pre-defined size' do
|
93
|
+
setup do
|
94
|
+
start_area
|
95
|
+
@area.stub!(:sizes).and_return({:standard => {:height => 11.0, :width => 8.5, :unit => 'inches'}})
|
96
|
+
@area.set_size :standard
|
97
|
+
end
|
98
|
+
|
99
|
+
specify 'the height should match with the selected size' do
|
100
|
+
@area.size[:height].should == @area.sizes[:standard][:height]
|
101
|
+
end
|
102
|
+
|
103
|
+
specify 'the height should match with the selected size' do
|
104
|
+
@area.size[:height].should == @area.sizes[:standard][:height]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'the coordinates of an area should' do
|
109
|
+
setup do
|
110
|
+
@area = Area.new([0,0])
|
111
|
+
end
|
112
|
+
specify 'have an horizontal element' do
|
113
|
+
@area.coordinates[:x].should_be_kind_of Float
|
114
|
+
end
|
115
|
+
specify 'have an vertical element' do
|
116
|
+
@area.coordinates[:y].should_be_kind_of Float
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when finding the size in some options' do
|
121
|
+
setup do
|
122
|
+
@area = Area.new([0,0])
|
123
|
+
end
|
124
|
+
specify 'should send the height back as 100% if no height is sent' do
|
125
|
+
@area.find_size_in({:width => '50%'})[:height].should == '100%'
|
126
|
+
end
|
127
|
+
specify 'should send the width back as 100% if no width is sent' do
|
128
|
+
@area.find_size_in({:height => '50%'})[:width].should == '100%'
|
129
|
+
end
|
130
|
+
specify 'should set the width if send on [:width]' do
|
131
|
+
@area.find_size_in({:width => '50%'})[:width].should == '50%'
|
132
|
+
end
|
133
|
+
specify 'should set the width if send on [:size][:width]' do
|
134
|
+
@area.find_size_in(:size => {:width => '50%'})[:width].should == '50%'
|
135
|
+
end
|
136
|
+
specify 'should set the height if send on [:height]' do
|
137
|
+
@area.find_size_in({:height => '50%'})[:height].should == '50%'
|
138
|
+
end
|
139
|
+
specify 'should set the height if send on [:size][:height]' do
|
140
|
+
@area.find_size_in(:size => {:height => '50%'})[:height].should == '50%'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when convertin percentages' do
|
145
|
+
setup do
|
146
|
+
@area = Area.new [0,0]
|
147
|
+
@area.set_size({:width => 11.0, :height => 8.5, :unit => 'inches'})
|
148
|
+
end
|
149
|
+
specify 'the numbers should come back as floats' do
|
150
|
+
@area.convert_percentages(:height => '100%')[:height].should_be_kind_of Float
|
151
|
+
end
|
152
|
+
specify 'the numbers should come back correctly' do
|
153
|
+
@area.convert_percentages(:height => '100%')[:height].should == @area.size[:height]
|
154
|
+
@area.convert_percentages(:height => '50%')[:height].should == @area.size[:height]/2
|
155
|
+
@area.convert_percentages(:height => '25%')[:height].should == @area.size[:height]/4
|
156
|
+
end
|
157
|
+
specify 'should just move on through if a faulty dimension is given' do
|
158
|
+
@area.convert_percentages(:bully => '25%').should == {:bully => '25%'}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'when defining the size from some options' do
|
163
|
+
setup do
|
164
|
+
@area = Area.new([0,0])
|
165
|
+
@area.set_size({:width => 11.0, :height => 8.5, :unit => 'inches'})
|
166
|
+
end
|
167
|
+
specify 'the height should be a float' do
|
168
|
+
@area.define_size_from({})[:height].should_be_kind_of Float
|
169
|
+
@area.define_size_from({:height => 5})[:height].should_be_kind_of Float
|
170
|
+
@area.define_size_from({:height => 5.0})[:height].should_be_kind_of Float
|
171
|
+
@area.define_size_from({:height => '50%'})[:height].should_be_kind_of Float
|
172
|
+
end
|
173
|
+
specify 'the width should be a float' do
|
174
|
+
@area.define_size_from({})[:width].should_be_kind_of Float
|
175
|
+
@area.define_size_from({:width => 5.0})[:width].should_be_kind_of Float
|
176
|
+
@area.define_size_from({:width => '50%'})[:width].should_be_kind_of Float
|
177
|
+
end
|
178
|
+
specify 'the units should be the same as the parent' do
|
179
|
+
@area.define_size_from({})[:unit].should == @area.size[:unit]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'when making a sub area' do
|
184
|
+
setup do
|
185
|
+
@area = Area.new([0, 0])
|
186
|
+
@area.stub!(:coordinates).and_return({:x=>0, :y=>0})
|
187
|
+
@area.stub!(:size).and_return({:width => 11.0, :height =>8.5})
|
188
|
+
@area.should_receive(:next_sub_coords).and_return({:x=>0, :y=>0})
|
189
|
+
@sub = @area.make_sub_area({:size => {:height => 3, :width =>5}})
|
190
|
+
end
|
191
|
+
|
192
|
+
specify 'info about the area should be returned' do
|
193
|
+
@sub.should_be_kind_of Area
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when opening a new area in an empty area' do
|
198
|
+
setup do
|
199
|
+
@area = Area.new([0, 0])
|
200
|
+
@area.stub!(:coordinates).and_return({:x=>0, :y=>0})
|
201
|
+
@area.stub!(:size).and_return({:width => 11.0, :height =>8.5})
|
202
|
+
@sub = @area.area({:size => {:height => 3, :width =>5}})
|
203
|
+
end
|
204
|
+
|
205
|
+
specify 'the coordinates found should be the coordinates of the parent' do
|
206
|
+
@sub.coordinates.should == @area.coordinates
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'when in an empty area' do
|
211
|
+
setup do
|
212
|
+
@area = Area.new([0, 0])
|
213
|
+
@area.set_size({:width => 11.0, :height =>8.5, :unit=>'inches'})
|
214
|
+
end
|
215
|
+
|
216
|
+
specify 'the next coordinates should be the coordinates of the parent' do
|
217
|
+
@area.next_sub_coords.should == @area.coordinates
|
218
|
+
end
|
219
|
+
|
220
|
+
specify 'should be able to create a sub area within the dimensions of this area' do
|
221
|
+
lambda{@area.area(:width => '50%')}.should_not_raise
|
222
|
+
end
|
223
|
+
specify 'should rais an error when creating a sub area exceeding the dimensions of this area' do
|
224
|
+
lambda{@area.area(:width => '110%')}.should_raise DoNotWant
|
225
|
+
end
|
226
|
+
specify 'should be able to create two areas' do
|
227
|
+
lambda{@area.area(:width => '20%')}.should_not_raise
|
228
|
+
lambda{@area.area(:width => '30%')}.should_not_raise
|
229
|
+
lambda{@area.area(:width => '70%')}.should_raise DoNotWant
|
230
|
+
end
|
231
|
+
|
232
|
+
specify 'should be able to create a sub area within the dimensions of this area' do
|
233
|
+
lambda{@area.area(:height => '50%')}.should_not_raise
|
234
|
+
end
|
235
|
+
specify 'should rais an error when creating a sub area exceeding the dimensions of this area' do
|
236
|
+
lambda{@area.area(:height => '110%')}.should_raise DoNotWant
|
237
|
+
end
|
238
|
+
specify 'should be able to create multiple areas' do
|
239
|
+
lambda{@area.area(:height => '20%')}.should_not_raise
|
240
|
+
lambda{@area.area(:height => '30%')}.should_not_raise
|
241
|
+
lambda{@area.area(:height => '50%')}.should_not_raise
|
242
|
+
lambda{@area.area(:height => '70%')}.should_raise DoNotWant
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'after adding an area' do
|
247
|
+
setup do
|
248
|
+
@area = Area.new([0, 0])
|
249
|
+
@area.set_size({:width => 10.0, :height =>8.5, :unit=>'inches'})
|
250
|
+
@area.area(:width => '50%')
|
251
|
+
end
|
252
|
+
|
253
|
+
specify 'the next sub coords should start at [5.5, 0]' do
|
254
|
+
@area.next_sub_coords.should == [5.0, 0]
|
255
|
+
end
|
256
|
+
specify 'trying again' do
|
257
|
+
@area.area(:width => '25%')
|
258
|
+
@area.next_sub_coords.should == [7.50, 0]
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'when rendering an area' do
|
263
|
+
setup do
|
264
|
+
@area = Area.new([0, 0])
|
265
|
+
@area.set_size({:width => 11.0, :height =>8.5, :unit=>'inches'})
|
266
|
+
end
|
267
|
+
|
268
|
+
specify 'should give the coordinates' do
|
269
|
+
@area.recording[:coords].should == [0, 0]
|
270
|
+
end
|
271
|
+
specify 'should give the dimensions' do
|
272
|
+
@area.recording[:dimensions].should == [11.0, 8.5]
|
273
|
+
end
|
274
|
+
specify 'should give the units' do
|
275
|
+
@area.recording[:units].should == "inches"
|
276
|
+
end
|
277
|
+
end
|
data/spec/page_specs.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../lib/area'
|
2
|
+
require File.dirname(__FILE__)+'/../lib/page'
|
3
|
+
|
4
|
+
context 'the orientation of an area should' do
|
5
|
+
setup do
|
6
|
+
@page = Page.new
|
7
|
+
@page.stub!(:coordinates).and_return({:x=>0, :y=>0})
|
8
|
+
@page.stub!(:border).and_return({})
|
9
|
+
@page.set_size({:long => 11.0, :short => 8.5, :unit => 'inches'})
|
10
|
+
end
|
11
|
+
specify 'not raise if it is portrait' do
|
12
|
+
lambda{@page.apply_orientation(:portrait)}.should_not_raise
|
13
|
+
end
|
14
|
+
specify 'not raise if it is landscape' do
|
15
|
+
lambda{@page.apply_orientation(:landscape)}.should_not_raise
|
16
|
+
end
|
17
|
+
specify 'raise otherwise' do
|
18
|
+
lambda{@page.apply_orientation(:bullschnitzle)}.should_raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when setting the orientation to portrait' do
|
23
|
+
setup do
|
24
|
+
@page = Page.new
|
25
|
+
@page.set_size({:long => 11.0, :short => 8.5, :unit => 'inches'})
|
26
|
+
@page.apply_orientation :portrait
|
27
|
+
end
|
28
|
+
|
29
|
+
specify 'the long side of the size will become the height' do
|
30
|
+
@page.size[:height].should == @page.size[:long].to_f
|
31
|
+
end
|
32
|
+
specify 'the short side of the size will become the width' do
|
33
|
+
@page.size[:width].should == @page.size[:short].to_f
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when setting the orientation to landscape' do
|
38
|
+
setup do
|
39
|
+
@page = Page.new
|
40
|
+
@page.set_size({:long => 11.0, :short => 8.5, :unit => 'inches'})
|
41
|
+
@page.apply_orientation :landscape
|
42
|
+
end
|
43
|
+
|
44
|
+
specify 'the long side of the size will become the width' do
|
45
|
+
@page.size[:width].should == @page.size[:long].to_f
|
46
|
+
end
|
47
|
+
specify 'the short side of the size will become the height' do
|
48
|
+
@page.size[:height].should == @page.size[:short].to_f
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: laysl
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-06-01 00:00:00 -04:00
|
8
|
+
summary: The author was too lazy to write a summary
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ryand-ruby@zenspider.com
|
12
|
+
homepage: http://www.zenspider.com/ZSS/Products/laysl/
|
13
|
+
rubyforge_project: laysl
|
14
|
+
description: The author was too lazy to write a description
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Ryan Davis
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/laysl
|
37
|
+
- lib/laysl.rb
|
38
|
+
- lib/area.rb
|
39
|
+
- lib/context/example.rb
|
40
|
+
- lib/context/header.rb
|
41
|
+
- lib/context/load.rb
|
42
|
+
- lib/context/areas/buffer.rb
|
43
|
+
- lib/context/areas/page.rb
|
44
|
+
- spec/area_specs.rb
|
45
|
+
- spec/page_specs.rb
|
46
|
+
test_files: []
|
47
|
+
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
extra_rdoc_files: []
|
51
|
+
|
52
|
+
executables:
|
53
|
+
- laysl
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
dependencies:
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: hoe
|
61
|
+
version_requirement:
|
62
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.2.0
|
67
|
+
version:
|