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

Phlex::SVG #493

Merged
merged 7 commits into from Feb 17, 2023
Merged

Phlex::SVG #493

merged 7 commits into from Feb 17, 2023

Conversation

davekaro
Copy link
Contributor

@davekaro davekaro commented Feb 16, 2023

Following up on #492. Mostly adding the remaining SVG tags. Still needs more tests and work.

SVG element list available https://www.w3.org/TR/SVG2/eltindex.html

Example

class Icon < Phlex::SVG
  def template
    svg("viewBox" => "0 0 100 100" xmlns: "http://www.w3.org/2000/svg") do
      path(d: "M 10,30
        A 20,20 0,0,1 50,30
        A 20,20 0,0,1 90,30
        Q 90,60 50,90
        Q 10,60 10,30 z"
      )
    end
  end
end

The SVG tags g and path are being removed from Phlex::HTML as they were a bit of a hack, but the svg tag now yields a new Phlex::SVG which can be used inline.

class Icon < Phlex::HTML
  def template
    svg("viewBox" => "0 0 100 100" xmlns: "http://www.w3.org/2000/svg") do |s|
      s.path(d: "M 10,30
        A 20,20 0,0,1 50,30
        A 20,20 0,0,1 90,30
        Q 90,60 50,90
        Q 10,60 10,30 z"
      )
    }
  end
end

joeldrapper and others added 4 commits February 15, 2023 20:55
Co-Authored-By: Dave Kroondyk <21263+davekaro@users.noreply.github.com>
In HTML, SVG is considered a foreign element and must either have a
start tag and an end tag, or a start tag that is marked as self-closing,
in which case they must not have an end tag. See
https://html.spec.whatwg.org/multipage/syntax.html#foreign-elements for
details. Most (all?) of these SVG elements can have child elements too,
mainly descriptive elements like ‘desc’, ‘metadata’ and ‘title’.
@joeldrapper joeldrapper mentioned this pull request Feb 16, 2023
@joeldrapper
Copy link
Collaborator

This is looking really great. I will follow up with a closer review soon.

lib/phlex/xml.rb Outdated
end

module Phlex
class XML
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

@marcoroth marcoroth Feb 17, 2023

Choose a reason for hiding this comment

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

I feel like SGML is weird, because no one knows this by heart. Also Nokogiri uses XML throughout their lib for representing XML and HTML nodes.

Or otherwise, also provide a XML < SGML class 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Users of Phlex probably don't need to know about the SGML class, right? I think SGML makes sense, and could see a future Phlex::XML to generate strict XML.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I would like to have a Phlex::XML class for working with strict XML with support for namespaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough 👍🏼

@joeldrapper joeldrapper marked this pull request as ready for review February 17, 2023 15:13
@joeldrapper
Copy link
Collaborator

I think this could do with a fair amount of refactoring, but it's a huge PR and it works and I’d like to merge it sooner rather than later so it doesn't get out of sync with other work.

@joeldrapper joeldrapper merged commit 09497b3 into phlex-ruby:main Feb 17, 2023
@davekaro davekaro deleted the svg branch February 17, 2023 15:44
@davekaro davekaro mentioned this pull request Feb 17, 2023
joeldrapper added a commit that referenced this pull request Mar 8, 2023
Following up on #492. Mostly
adding the remaining SVG tags. Still needs more tests and work.

SVG element list available https://www.w3.org/TR/SVG2/eltindex.html

### Example

```ruby
class Icon < Phlex::SVG
  def template
    svg("viewBox" => "0 0 100 100" xmlns: "http://www.w3.org/2000/svg") do
      path(d: "M 10,30
        A 20,20 0,0,1 50,30
        A 20,20 0,0,1 90,30
        Q 90,60 50,90
        Q 10,60 10,30 z"
      )
    end
  end
end
```

The SVG tags are being removed from Phlex::HTML as they were a bit of a
hack, but the `svg` tag now yields a new `Phlex::SVG` which can be used
inline.

```ruby
class Icon < Phlex::HTML
  def template
    svg("viewBox" => "0 0 100 100" xmlns: "http://www.w3.org/2000/svg") do |s|
      s.path(d: "M 10,30
        A 20,20 0,0,1 50,30
        A 20,20 0,0,1 90,30
        Q 90,60 50,90
        Q 10,60 10,30 z"
      )
    }
  end
end
```

---------

Co-authored-by: Joel Drapper <joel@drapper.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants