7 changed files with 77 additions and 2 deletions
@ -0,0 +1,19 @@
|
||||
mm |
||||
------ |
||||
|
||||
Given millimeters, returns the number of pixels according to the deck's DPI. |
||||
|
||||
Parameters |
||||
^^^^^^^^^^ |
||||
|
||||
n |
||||
the number of mm |
||||
|
||||
|
||||
Examples |
||||
^^^^^^^^ |
||||
|
||||
.. code-block:: ruby |
||||
|
||||
mm(1) # 11.811px (for default Deck::dpi of 300) |
||||
mm(2) + mm(1) # 35.433ox (for default Deck::dpi of 300) |
||||
@ -1,6 +1,6 @@
|
||||
Unit Conversion |
||||
=============== |
||||
|
||||
By default, Squib thinks in pixels. This decision was made so that we can have pixel-perfect layouts without automatically scaling everything, even though working in units is sometimes easier. We provide some conversion methods, including looking for strings that end in "in" and "cm" and computing based on the current DPI. The dpi is set on `Squib::Deck.new` (not `config.yml`). |
||||
By default, Squib thinks in pixels. This decision was made so that we can have pixel-perfect layouts without automatically scaling everything, even though working in units is sometimes easier. We provide some conversion methods, including looking for strings that end in "in", "cm", or "mm" and computing based on the current DPI. The dpi is set on `Squib::Deck.new` (not `config.yml`). |
||||
|
||||
Example is in `samples/units.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/units.rb) |
||||
|
||||
@ -0,0 +1,37 @@
|
||||
require 'spec_helper' |
||||
|
||||
describe Squib::Deck do |
||||
|
||||
let(:deck) { Squib::Deck.new } |
||||
|
||||
context '#in' do |
||||
it 'converts inches properly' do |
||||
expect(deck.inches(1)).to eq 300 |
||||
end |
||||
|
||||
it 'handles strings too' do |
||||
expect(deck.inches('1')).to eq 300 |
||||
end |
||||
end |
||||
|
||||
context '#cm' do |
||||
it 'converts inches properly' do |
||||
expect(deck.cm(1)).to eq 118.1102361 |
||||
end |
||||
|
||||
it 'handles strings too' do |
||||
expect(deck.cm('1')).to eq 118.1102361 |
||||
end |
||||
end |
||||
|
||||
context '#mm' do |
||||
it 'converts inches properly' do |
||||
expect(deck.mm(1)).to eq 11.81102361 |
||||
end |
||||
|
||||
it 'handles strings too' do |
||||
expect(deck.mm('1')).to eq 11.81102361 |
||||
end |
||||
end |
||||
|
||||
end |
||||
Loading…
Reference in new issue