Cristagiri
An Html parser library for Crystal like amazing Nokogiri Ruby gem.
I not pretend that Cristagiri does much as Nokogiri. All help will be welcome! :)
Installation
Add this to your application's shard.yml
:
dependencies:
cristagiri:
github: madeindjs/cristagiri
and then run
$ crystal deps
Usage
require "cristagiri"
Then you can simply instanciate a Cristagiri::HTML
from a Html String
like this
doc = Cristagiri::HTML.new "<h1>Cristagiri is awesome!!</h1>"
... or directly load it from a Web Url or a pathname:
doc = Cristagiri::HTML.from_file "README.md"
doc = Cristagiri::HTML.from_url "http://example.com/"
Then you can search XML::Node
from Cristagiri::HTML
instance:
# find by id
puts doc.at_id("main-content") # => <div id="main-content"> ... </div>
# 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 }
Development
Clone this repository and go in it:
$ git clone https://github.com/madeindjs/cristagiri.git
$ cd cristagiri
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/cristagiri/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