Class: BorderTools
- Inherits:
-
Generator
- Object
- Generator
- BorderTools
- Defined in:
- lib/border_tools.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #background_color ⇒ Object
- #draw(image, *args) ⇒ Object
- #sass(class_name) ⇒ Object
- #set_source ⇒ Object
- #slice(sizeX, sizeY, offsetX, offsetY) ⇒ Object
- #write_css(name) ⇒ Object
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/border_tools.rb', line 3 def size @size end |
Class Method Details
.inherited(c) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/border_tools.rb', line 76 def self.inherited(c) c.image :tl do slice(size, size, 0, 0) end c.image :tc do slice(1, size, size + 1, 0) end c.image :tr do slice(size, size, @border.width - size, 0) end c.image :cl do slice(size, 1, 0, size + 1) end c.image :cr do slice(size, 1, @border.width - size, size + 1) end c.image :bl do slice(size, size, 0, @border.height - size) end c.image :bc do slice(1, size, size + 1, @border.height - size) end c.image :br do slice(size, size, @border.width - size, @border.height - size) end c.image :border, :suite => false do draw_border end end |
.preview(image = :border, *args) ⇒ Object
5 6 7 |
# File 'lib/border_tools.rb', line 5 def self.preview(image=:border, *args) super end |
.suite(prefix, *args) ⇒ Object
9 10 11 12 |
# File 'lib/border_tools.rb', line 9 def self.suite(prefix, *args) super self.new.write_css(prefix) end |
Instance Method Details
#background_color ⇒ Object
71 72 73 74 |
# File 'lib/border_tools.rb', line 71 def background_color set_source @border.get_pixel(@border.width/2, @border.height/2) end |
#draw(image, *args) ⇒ Object
14 15 16 17 |
# File 'lib/border_tools.rb', line 14 def draw(image, *args) @args = args super end |
#sass(class_name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/border_tools.rb', line 27 def sass(class_name) %{ table.#{class_name} border-collapse: collapse padding: 0 margin: 0 .#{class_name} &.tl, &.tr, &.bl, &.br, &.tc, &.bc height: #{size}px !important padding: 0 !important border: 0 margin: 0 &.tl, &.bl, &.tr, &.br, &.cl, &.cr width: #{size}px !important padding: 0 !important border: 0 margin: 0 &.tl background: url(/images/#{class_name}_tl.png) &.tr background: url(/images/#{class_name}_tr.png) &.bl background: url(/images/#{class_name}_bl.png) &.br background: url(/images/#{class_name}_br.png) &.cl background: url(/images/#{class_name}_cl.png) &.tc background: url(/images/#{class_name}_tc.png) &.cr background: url(/images/#{class_name}_cr.png) &.bc background: url(/images/#{class_name}_bc.png) &.content background-color: #{background_color.to_css} } end |
#set_source ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/border_tools.rb', line 19 def set_source unless @source draw_border(*(@args || [])) @border = @surface @source = Cairo::SurfacePattern.new(@border) end end |
#slice(sizeX, sizeY, offsetX, offsetY) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/border_tools.rb', line 114 def slice(sizeX, sizeY, offsetX, offsetY) set_source dimensions sizeX, sizeY cr.set_source(@source) cr.source.matrix = Cairo::Matrix.identity.translate(offsetX, offsetY) cr.paint end |
#write_css(name) ⇒ Object
65 66 67 68 69 |
# File 'lib/border_tools.rb', line 65 def write_css(name) set_source path = File.join(File.dirname(__FILE__), "../public/stylesheets/sass/#{name}.sass") File.open(path, 'w') {|f| f << sass(name)} end |