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

A fourth composite pull request #80

Merged
merged 14 commits into from
Oct 15, 2019
Merged
Changes from 1 commit
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
28 changes: 21 additions & 7 deletions opal/browser/css.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,33 @@
require 'browser/css/rule/style'

module Kernel
# Create a <style> element from a string or a block using the
# {Paggio::CSS} DSL.
# @overload CSS(document = $document, &block)
#
# @param text [String] the CSS text
# @return [Browser::DOM::Element] the create <style> element
def CSS(text = nil, &block)
style = $document.create_element(:style)
# Create a `<style>` element from a {Paggio::CSS} DSL.
#
# @param document [Browser::DOM::Document] the document instance
# we intend to use
#
# @return [Browser::DOM::Element] the created `<style>` element
#
# @overload CSS(string, document = $document)
#
# Create a `<style>` element from a string.
#
# @param document [Browser::DOM::Document] the document instance
# we intend to use
#
# @return [Browser::DOM::Element] the created `<style>` element
def CSS(*args, &block)
document = args.pop || $document
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this, I think, needs to be solved in another way, what if I just pass the css text as first argument… wouldn't it pop the last element from args which happens to also be the first one?

I'd suggest def CSS(text = nil, document = $document, &block), or a check to see if the argument is a String, or —maybe better— use the if block check as it's done in DOM(…).


style = document.create_element(:style)
style[:type] = 'text/css'

if block
style.inner_text = Paggio.css(&block)
else
style.inner_text = text
style.inner_text = args.join("")
end

style
Expand Down