Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for margin in para #477

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/margin/combine_margin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Shoes.app do
para 'Hii', margin: 10, margin_left: 20
end
3 changes: 3 additions & 0 deletions examples/margin/margin_left.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Shoes.app do
para "hi" ,margin_left: "20"
end
4 changes: 4 additions & 0 deletions examples/margin/margin_top.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Shoes.app do
para "hi" ,margin_top: "20"
end

16 changes: 16 additions & 0 deletions scarpe-components/lib/scarpe/components/calzini/para.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,25 @@ def para_style(props)
color: rgb_to_hex(props["stroke"]),
"font-size": para_font_size(props),
"font-family": props["font"],
"margin": calculate_margin(props['html_attributes'])
}.compact)
end

def calculate_margin(props)
margin = {top: props[:margin_top], right: props[:margin_right], bottom: props[:margin_bottom], left: props[:margin_left]}
margin = margin.transform_values { |val| (val || 0).to_i }

case props[:margin]
when Integer
margin = margin.transform_values{|val| val + props[:margin]}
when Array
new_margin = {top: props[:margin][0].to_i, right: props[:margin][1].to_i, bottom: props[:margin][2].to_i, left: props[:margin][3].to_i}
margin.merge!(margin, new_margin) { |key, old_value, new_value| old_value + new_value }
end

"#{margin[:top]}px #{margin[:right]}px #{margin[:bottom]}px #{margin[:left]}px"
end

def para_font_size(props)
return nil unless props["size"]

Expand Down
Loading