• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

plexus / hexp / 36
93%
master: 100%

Build:
Build:
LAST BUILD BRANCH: v0.4.4
DEFAULT BRANCH: master
Ran 26 Jun 2013 08:01PM UTC
Jobs 5
Files 249
Run time 635166min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
36

push

travis-ci

plexus
Experiment with chainable selectors and rewriters

This commit introduces a first attempt at coming up with a chainable interface
for describing transformations of Hexp trees.

The idea is to have certain methods that select certain nodes in a tree. At
this point there is one such method : select, which takes a block that receives
a node and returns a boolean.

  node.select {|child_node| child_node.class? 'strong' }

The result is a Hexp::Node::Selector, it is Enumerable, so one can do #to_a, #map,
etc and to loop over the nodes in the tree that have class="strong".

This can be combined with the concept of "rewriting" a tree, here the block receives
a node, and the return value of the block takes the place of the original node in the
new, rewritten tree.

This return value can be a single node or an array of nodes (zero or more). Nil is
treated special in that it is consider a no-op. When the block returns nil, the
original node is simply kept in the tree unaltered.

This example will give every <p> the class "para".

  node.rewrite do |child_node|
    if child_node.tag == :p
      child_node.attr('class', 'para')}
    end
  end

Nodes and Selectors both respond to #rewrite, in the latter case only the nodes
that match the selection criterium are passed to the block, so the former example
can be rewritten as

  node.select  {|child| child.tag == :p}
      .rewrite {|child| child_node.attr('class', 'para') }

The result is an instance of Hexp::Node::Rewriter, which lazily evaluates the
transformation when converted to a Hexp. It includes Hexp::DSL, so it can be
used as any Hexp::Node (tag, attributes, to_html, etc).

These two can form the basic building blocks for a richer API. As a tryout they
already implement #wrap and #attr, so to take every paragraph, give it the class
'para', and wrap it in a div with class 'wrapper' you can write

  node.select {|child| child.tag == :p}
      .attr('class', 'para')
      .wrap(:div, 'class' => 'wrapper')

The... (continued)

70 of 70 new or added lines in 6 files covered. (100.0%)

4965 of 6010 relevant lines covered (82.61%)

27.17 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
1
100.0
lib/hexp/node.rb
1
100.0
lib/hexp/node/domize.rb
10
100.0
lib/hexp/node/selector.rb
13
100.0
lib/hexp/node/rewriter.rb
Jobs
ID Job ID Ran Files Coverage
1 36.1 (1.9.2) 10 Sep 2014 10:05PM UTC 0
81.45
Travis Job 36.1
2 36.2 (1.9.3) 10 Sep 2014 10:05PM UTC 0
81.45
Travis Job 36.2
3 36.3 (2.0.0) 26 Jun 2013 08:03PM UTC 0
93.79
Travis Job 36.3
4 36.4 (jruby-19mode) 26 Jun 2013 08:01PM UTC 0
92.43
Travis Job 36.4
5 36.5 (jruby-head) 26 Jun 2013 08:01PM UTC 0
92.43
Travis Job 36.5
Source Files on build 36
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #36
  • 7d1ad9f3 on github
  • Next Build on chainable_api_rfc (#38)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc