-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
183 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Shoes.app do | ||
|
||
para "All margins with array input", margin:[60,30,80,40] | ||
|
||
para "All margins with string input", margin: "30 20 10 20" | ||
|
||
para "One Number to set all margins", margin:20 | ||
|
||
para "Specific property can overwrite shorthand" , margin:[20,10,20,30], margin_top:100 | ||
|
||
para "margins using a hash input" , margin:{left:20,top:100,bottom:10,right:20} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module MarginHelper | ||
|
||
def margin_parse(kwargs) | ||
|
||
if kwargs[:margin] | ||
|
||
if kwargs[:margin].is_a?(Numeric) | ||
|
||
return kwargs | ||
elsif kwargs[:margin].is_a?(Hash) | ||
|
||
kwargs[:margin].each do |key,value| | ||
kwargs[:"margin_#{key}"] = value | ||
end | ||
|
||
else | ||
margin_props = kwargs[:margin].is_a?(String) ? kwargs[:margin].split(/\s+|\,|-/) : kwargs[:margin] | ||
if margin_props.length == 1 | ||
|
||
kwargs[:margin] = margin_props[0] | ||
return kwargs | ||
|
||
elsif margin_props.length == 2 | ||
|
||
raise(Shoes::Errors::InvalidAttributeValueError, "Margin don't support 2-3 values as Array/string input for using 2-3 input you can use the hash input method like '{left:value, right:value, top:value, bottom:value}'") | ||
|
||
elsif margin_props.length == 3 | ||
|
||
raise(Shoes::Errors::InvalidAttributeValueError, "Margin don't support 2-3 values as Array/string input for using 2-3 input you can use the hash input method like '{left:value,right:value,top:value,bottom:value}'") | ||
|
||
else | ||
|
||
if !kwargs[:margin_top] | ||
kwargs[:margin_top] = margin_props[1] | ||
end | ||
if !kwargs[:margin_bottom] | ||
kwargs[:margin_bottom] = margin_props[3] | ||
end | ||
if !kwargs[:margin_left] | ||
kwargs[:margin_left] = margin_props[0] | ||
end | ||
if !kwargs[:margin_right] | ||
kwargs[:margin_right] = margin_props[2] | ||
end | ||
|
||
end | ||
end | ||
kwargs[:margin] = nil | ||
end | ||
if kwargs["options"] && !kwargs[:margin] && !kwargs[:margin_left] && !kwargs[:margin_right] && !kwargs[:margin_top] && !kwargs[:margin_bottom] | ||
kwargs[options].each do |key,value| | ||
kwargs[key] = value | ||
end | ||
end | ||
kwargs | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# frozen_string_literal: true | ||
|
||
load "lacci/lib/shoes/margin_helper.rb" | ||
|
||
|
||
class TestMarginHelper < Minitest::Test | ||
include MarginHelper | ||
|
||
def test_one_Number_margin | ||
|
||
kwargs = {:margin => 20} | ||
|
||
assert_equal({:margin => 20},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
def test_Array_four_margin | ||
|
||
kwargs = {:margin => [20,20,30,40]} | ||
|
||
assert_equal({:margin => nil, :margin_left => 20, :margin_top => 20, :margin_right => 30, :margin_bottom => 40},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
def test_Array_one_margin | ||
|
||
kwargs = {:margin => [20]} | ||
|
||
assert_equal({:margin => 20},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
|
||
def test_String_four_margin | ||
|
||
kwargs = {:margin => "20 30 40 50"} | ||
|
||
assert_equal({:margin => nil, :margin_left => "20", :margin_top => "30", :margin_right => "40", :margin_bottom => "50"},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
def test_String_one_margin | ||
|
||
kwargs = {:margin => "20"} | ||
|
||
assert_equal({:margin => "20"},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
def test_Hash_four_margin | ||
|
||
kwargs = {:margin => {left:20,top:20,right:30,bottom:30}} | ||
|
||
assert_equal({:margin => nil, :margin_left => 20, :margin_top => 20, :margin_right => 30, :margin_bottom => 30},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
def test_Hash_three_margin | ||
|
||
kwargs = {:margin => {top:20,right:30,bottom:30}} | ||
|
||
assert_equal({:margin => nil, :margin_top => 20, :margin_right => 30, :margin_bottom => 30},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
def test_Hash_two_margin | ||
|
||
kwargs = {:margin => {left:20,top:20}} | ||
|
||
assert_equal({:margin => nil, :margin_left => 20, :margin_top => 20},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
def test_Hash_one_margin | ||
|
||
kwargs = {:margin => {bottom:30}} | ||
|
||
assert_equal({:margin => nil, :margin_bottom => 30},margin_parse(kwargs)) | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div id="2" style="display:flex;flex-direction:row;flex-wrap:wrap;align-content:flex-start;justify-content:flex-start;align-items:flex-start;width:100%;height:100%"> | ||
<div style="height:100%;width:100%;position:relative"> | ||
<p id="3" style="margin-left:60px;margin-right:80px;margin-top:30px;margin-bottom:40px;font-size:12px">All margins with array input</p> | ||
<p id="4" style="margin-left:30;margin-right:10;margin-top:20;margin-bottom:20;font-size:12px">All margins with string input</p> | ||
<p id="5" style="margin:20px;font-size:12px">One Number to set all margins</p> | ||
<p id="6" style="margin-left:20px;margin-right:20px;margin-top:100px;margin-bottom:30px;font-size:12px">Specific property can overwrite shorthand</p> | ||
<p id="7" style="margin-left:20px;margin-right:20px;margin-top:100px;margin-bottom:10px;font-size:12px">margins using a hash input</p> | ||
<div id="root-fonts"></div> | ||
<div id="root-alerts"> </div> | ||
</div> | ||
</div> |