Crystagiri
An Html parser library for Crystal like amazing Nokogiri Ruby gem.
I not pretend that Crystagiri does much as Nokogiri. All help will be welcome! :)
Installation
Add this to your application's shard.yml
:
dependencies:
crystagiri:
github: madeindjs/crystagiri
and then run
$ crystal deps
Usage
require "crystagiri"
Then you can simply instanciate a Crystagiri::HTML
from a Html String
like this
doc = Crystagiri::HTML.new "<h1>Crystagiri is awesome!!</h1>"
... or directly load it from a Web Url or a pathname:
doc = Crystagiri::HTML.from_file "README.md"
doc = Crystagiri::HTML.from_url "http://example.com/"
Then you can search XML::Node
from Crystagiri::HTML
instance:
# find by id
puts doc.at_id("main-content") # => <div id="main-content"> ... </div>
# Find by css query
doc.css("#main-content ol.steps") {|node| puts node}
# => <ol class="steps"> .. </ol>
doc.css("#body>quote.introduction") {|node| puts node}
# => <quote class="introduction"> .. </quote>
# find all tag by their classnames
doc.class("summary") { |node| puts node }
# => <div class="summary"> .. </div>
# => <div class="summary"> .. </div>
# => <div class="summary"> .. </div>
# find all tag by their types
doc.tag("h2") { |node| puts node }
Know limitations: For the moment you can't use css query with complex search like
:nth-child
Development
Clone this repository and go in it:
$ git clone https://github.com/madeindjs/crystagiri.git
$ cd crystagiri
You can generate the complete documentation with
$ crystal doc
And run spec tests to ensure all work correctly
$ crystal spec
Contributing
- Fork it ( https://github.com/madeindjs/crystagiri/fork )
- Create your feature branch
git checkout -b my-new-feature
- Commit your changes
git commit -am "Add some feature"
- Push to the branch
git push origin my-new-feature
- Create a new Pull Request
Contributors
- madeindjs - creator, maintainer