crystagiri

An Html Reader / parser like Nokogiri Ruby gem html-parser-library
0.2.0 released

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

  1. Fork it ( https://github.com/madeindjs/crystagiri/fork )
  2. Create your feature branch git checkout -b my-new-feature
  3. Commit your changes git commit -am "Add some feature"
  4. Push to the branch git push origin my-new-feature
  5. Create a new Pull Request

Contributors

crystagiri:
  github: madeindjs/Crystagiri
  version: ~> 0.2.0
License MIT
Crystal 0.20.1

Authors

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently