Skip to content

Commit 2dbe4fc

Browse files
committed
Udpated the README and bumped gem version
1 parent b74e22e commit 2dbe4fc

File tree

2 files changed

+66
-133
lines changed

2 files changed

+66
-133
lines changed

README.md

Lines changed: 65 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,7 @@
33
[![Gem Version](https://badge.fury.io/rb/motion-html-pipeline.svg)](http://badge.fury.io/rb/motion-html-pipeline)
44
[![Build Status](https://travis-ci.org/digitalmoksha/motion-html-pipeline.svg?branch=master)](https://travis-ci.org/digitalmoksha/motion-html-pipeline)
55

6-
This gem is a port of the [`html-pipeline` gem](https://github.com/jch/html-pipeline) to RubyMotion, for use on iOS and macOS. Currently synced with `html-pipeline` release [`v.2.11.0`](https://github.com/jch/html-pipeline/releases/tag/v2.11.0)
7-
8-
Several of the standard filters, such as `AutolinkFilter` and `EmojiFilter`, are initially disabled, as they rely on other Ruby gems that don't have RubyMotion equivalents. Please feel free to submit a pull request that enables any of them.
9-
10-
We use [HTMLKit](https://github.com/iabudiab/HTMLKit) to take the place of Nokogiri.
11-
12-
Below is a copy of the original README file, until I'm able to flesh this one out more.
13-
14-
But you can build a pipeline like this:
15-
16-
```ruby
17-
pipeline = MotionHTMLPipeline::Pipeline.new [
18-
MotionHTMLPipeline::Pipeline::HttpsFilter,
19-
MotionHTMLPipeline::Pipeline::ImageMaxWidthFilter
20-
]
21-
result = pipeline.call("<a href='http://example.com/one.png'>link</a> <img src='one.png'>", {http_url: 'http://example.com'})
22-
result[:output].to_s
23-
```
24-
25-
---
26-
# HTML::Pipeline
6+
_This gem is a port of the [`html-pipeline` gem](https://github.com/jch/html-pipeline) to RubyMotion, for use on iOS and macOS. Currently synced with `html-pipeline` release [`v.2.11.0`](https://github.com/jch/html-pipeline/releases/tag/v2.11.0)_
277

288
GitHub HTML processing filters and utilities. This module includes a small
299
framework for defining DOM based content filters and applying them to user
@@ -34,95 +14,93 @@ provided content. Read an introduction about this project in
3414
- [Usage](#usage)
3515
- [Examples](#examples)
3616
- [Filters](#filters)
37-
- [Dependencies](#dependencies)
17+
- [Disabled Filters](#disabled-filters)
3818
- [Documentation](#documentation)
3919
- [Extending](#extending)
4020
- [3rd Party Extensions](#3rd-party-extensions)
4121
- [Instrumenting](#instrumenting)
4222
- [Contributing](#contributing)
4323
- [Contributors](#contributors)
44-
- [Releasing A New Version](#releasing-a-new-version)
4524

4625
## Installation
4726

4827
Add this line to your application's Gemfile:
4928

5029
```ruby
51-
gem 'html-pipeline'
30+
gem 'motion-html-pipeline'
5231
```
5332

54-
And then execute:
33+
and to your `Rakefile`
5534

56-
```sh
57-
$ bundle
35+
```ruby
36+
require 'motion-html-pipeline'
5837
```
5938

60-
Or install it yourself as:
39+
And then execute:
6140

6241
```sh
63-
$ gem install html-pipeline
42+
$ bundle
6443
```
6544

6645
## Usage
6746

68-
This library provides a handful of chainable HTML filters to transform user
69-
content into markup. A filter takes an HTML string or
70-
`Nokogiri::HTML::DocumentFragment`, optionally manipulates it, and then
47+
This library provides a handful of chain-able HTML filters to transform user
48+
content into markup. A filter takes an HTML string or a
49+
`MotionHTMLPipeline::DocumentFragment`, optionally manipulates it, and then
7150
outputs the result.
7251

73-
For example, to transform Markdown source into Markdown HTML:
52+
For example, to transform an image URL into an image tag:
7453

7554
```ruby
76-
require 'html/pipeline'
77-
78-
filter = HTML::Pipeline::MarkdownFilter.new("Hi **world**!")
55+
filter = MotionHTMLPipeline::Pipeline::ImageFilter.new("http://example.com/test.jpg")
7956
filter.call
8057
```
8158

59+
would output
60+
61+
```html
62+
<img src="http://example.com/test.jpg" alt=""/>
63+
```
64+
8265
Filters can be combined into a pipeline which causes each filter to hand its
8366
output to the next filter's input. So if you wanted to have content be
84-
filtered through Markdown and be syntax highlighted, you can create the
85-
following pipeline:
67+
filtered through the `ImageFilter` and then wrap it in an `<a>` tag with
68+
a max-width inline style:
8669

8770
```ruby
88-
pipeline = HTML::Pipeline.new [
89-
HTML::Pipeline::MarkdownFilter,
90-
HTML::Pipeline::SyntaxHighlightFilter
91-
]
92-
result = pipeline.call <<-CODE
93-
This is *great*:
94-
95-
some_code(:first)
96-
97-
CODE
71+
pipeline = MotionHTMLPipeline::Pipeline.new([
72+
MotionHTMLPipeline::Pipeline::ImageFilter,
73+
MotionHTMLPipeline::Pipeline::ImageMaxWidthFilter
74+
])
75+
result = pipeline.call("http://example.com/test.jpg")
9876
result[:output].to_s
9977
```
10078

10179
Prints:
10280

10381
```html
104-
<p>This is <em>great</em>:</p>
105-
106-
<pre><code>some_code(:first)
107-
</code></pre>
82+
<a href="http://example.com/test.jpg" target="_blank"><img src="http://example.com/test.jpg" alt="" style="max-width:100%;"></a>
10883
```
10984

110-
To generate CSS for HTML formatted code, use the [Rouge CSS Theme](https://github.com/jneen/rouge#css-theme-options) `#css` method. `rouge` is a dependency of the `SyntaxHighlightFilter`.
111-
11285
Some filters take an optional **context** and/or **result** hash. These are
11386
used to pass around arguments and metadata between filters in a pipeline. For
114-
example, if you don't want to use GitHub formatted Markdown, you can pass an
115-
option in the context hash:
87+
example, with the `AbsoluteSourceFilter` you can pass in `:image_base_url` in
88+
the context hash:
89+
11690

11791
```ruby
118-
filter = HTML::Pipeline::MarkdownFilter.new("Hi **world**!", :gfm => false)
92+
filter = MotionHTMLPipeline::Pipeline::AbsoluteSourceFilter.new('<img src="/test.jpg">', image_base_url: 'http://example.com')
11993
filter.call
12094
```
12195

12296
### Examples
12397

12498
We define different pipelines for different parts of our app. Here are a few
125-
paraphrased snippets to get you started:
99+
paraphrased snippets to get you started.
100+
101+
_Note: these are examples from the original
102+
gem since they illustrate how the pipelines can be used. Many of the filters are
103+
not currently usable yet, as mentioned in the Filters section below._
126104

127105
```ruby
128106
# The context hash is how you pass options between different filters.
@@ -177,68 +155,51 @@ EmojiPipeline = Pipeline.new [
177155

178156
## Filters
179157

180-
* `MentionFilter` - replace `@user` mentions with links
181158
* `AbsoluteSourceFilter` - replace relative image urls with fully qualified versions
159+
* `HttpsFilter` - HTML Filter for replacing http github urls with https versions.
160+
* `ImageMaxWidthFilter` - link to full size image for large images
161+
162+
### Disabled Filters
163+
164+
Several of the standard filters, such as `AutolinkFilter` and `EmojiFilter`, are initially disabled, as they rely on other Ruby gems that don't have RubyMotion equivalents. Please feel free to submit a pull request that enables any of them.
165+
166+
* `MentionFilter` - replace `@user` mentions with links
182167
* `AutolinkFilter` - auto_linking urls in HTML
183168
* `CamoFilter` - replace http image urls with [camo-fied](https://github.com/atmos/camo) https versions
184169
* `EmailReplyFilter` - util filter for working with emails
185170
* `EmojiFilter` - everyone loves [emoji](http://www.emoji-cheat-sheet.com/)!
186-
* `HttpsFilter` - HTML Filter for replacing http github urls with https versions.
187-
* `ImageMaxWidthFilter` - link to full size image for large images
188171
* `MarkdownFilter` - convert markdown to html
189172
* `PlainTextInputFilter` - html escape text and wrap the result in a div
190173
* `SanitizationFilter` - whitelist sanitize user markup
191174
* `SyntaxHighlightFilter` - code syntax highlighter
192-
* `TextileFilter` - convert textile to html
193175
* `TableOfContentsFilter` - anchor headings with name attributes and generate Table of Contents html unordered list linking headings
194176

195-
## Dependencies
196-
197-
Filter gem dependencies are not bundled; you must bundle the filter's gem
198-
dependencies. The below list details filters with dependencies. For example,
199-
`SyntaxHighlightFilter` uses [rouge](https://github.com/jneen/rouge)
200-
to detect and highlight languages. For example, to use the `SyntaxHighlightFilter`,
201-
add the following to your Gemfile:
202-
203-
```ruby
204-
gem 'rouge'
205-
```
206-
207-
* `AutolinkFilter` - `rinku`
208-
* `EmailReplyFilter` - `escape_utils`, `email_reply_parser`
209-
* `EmojiFilter` - `gemoji`
210-
* `MarkdownFilter` - `commonmarker`
211-
* `PlainTextInputFilter` - `escape_utils`
212-
* `SanitizationFilter` - `sanitize`
213-
* `SyntaxHighlightFilter` - `rouge`
214-
* `TableOfContentsFilter` - `escape_utils`
215-
* `TextileFilter` - `RedCloth`
216-
217-
_Note:_ See [Gemfile](/Gemfile) `:test` block for version requirements.
218-
219177
## Documentation
220178

221-
Full reference documentation can be [found here](http://rubydoc.info/gems/html-pipeline/frames).
179+
Full reference documentation for the original `html-pipeline` gem can be [found here](http://rubydoc.info/gems/html-pipeline/frames).
222180

223181
## Extending
182+
224183
To write a custom filter, you need a class with a `call` method that inherits
225-
from `HTML::Pipeline::Filter`.
184+
from `MotionHTMLPipeline::Pipeline::Filter`.
226185

227186
For example this filter adds a base url to images that are root relative:
228187

229188
```ruby
230-
require 'uri'
231-
232-
class RootRelativeFilter < HTML::Pipeline::Filter
189+
class RootRelativeFilter < MotionHTMLPipeline::Pipeline::Filter
233190

234191
def call
235-
doc.search("img").each do |img|
192+
doc.css("img").each do |img|
236193
next if img['src'].nil?
194+
237195
src = img['src'].strip
196+
238197
if src.start_with? '/'
239-
img["src"] = URI.join(context[:base_url], src).to_s
198+
base_url = NSURL.URLWithString(context[:base_url])
199+
img["src"] = NSURL.URLWithString(src, relativeToURL: base_url).absoluteString
240200
end
241201
end
202+
242203
doc
243204
end
244205

@@ -248,15 +209,12 @@ end
248209
Now this filter can be used in a pipeline:
249210

250211
```ruby
251-
Pipeline.new [ RootRelativeFilter ], { :base_url => 'http://somehost.com' }
212+
Pipeline.new [ RootRelativeFilter ], { base_url: 'http://somehost.com' }
252213
```
253214

254215
### 3rd Party Extensions
255216

256-
If you have an idea for a filter, propose it as
257-
[an issue](https://github.com/jch/html-pipeline/issues) first. This allows us discuss
258-
whether the filter is a common enough use case to belong in this gem, or should be
259-
built as an external gem.
217+
Many people have built their own filters for [html-pipeline](https://github.com/jch/html-pipeline/issues). Although these have not been converted to run with RubyMotion, most of them should be easy convert.
260218

261219
Here are some extensions people have built:
262220

@@ -282,22 +240,25 @@ Here are some extensions people have built:
282240

283241
## Instrumenting
284242

243+
_Although instrumenting was ported, it has not been used real-world, and may not work
244+
properly at this time._
245+
285246
Filters and Pipelines can be set up to be instrumented when called. The pipeline
286247
must be setup with an
287248
[ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html)
288249
compatible service object and a name. New pipeline objects will default to the
289-
`HTML::Pipeline.default_instrumentation_service` object.
250+
`MotionHTMLPipeline::Pipeline.default_instrumentation_service` object.
290251

291252
``` ruby
292253
# the AS::Notifications-compatible service object
293254
service = ActiveSupport::Notifications
294255

295256
# instrument a specific pipeline
296-
pipeline = HTML::Pipeline.new [MarkdownFilter], context
257+
pipeline = MotionHTMLPipeline::Pipeline.new [MarkdownFilter], context
297258
pipeline.setup_instrumentation "MarkdownPipeline", service
298259

299260
# or set default instrumentation service for all new pipelines
300-
HTML::Pipeline.default_instrumentation_service = service
261+
MotionHTMLPipeline::Pipeline.default_instrumentation_service = service
301262
pipeline = HTML::Pipeline.new [MarkdownFilter], context
302263
pipeline.setup_instrumentation "MarkdownPipeline"
303264
```
@@ -332,6 +293,8 @@ end
332293

333294
## FAQ
334295

296+
_I have left this FAQ item here for when we get the `PlainTextInputFilter` working._
297+
335298
### 1. Why doesn't my pipeline work when there's no root element in the document?
336299

337300
To make a pipeline work on a plain text document, put the `PlainTextInputFilter`
@@ -353,38 +316,8 @@ html_fragment = "This is outside of an html element, but <strong>this isn't. :+1
353316
EmojiPipeline.call("<div>#{html_fragment}</div>") # <- Wrap your own html fragments to avoid escaping
354317
```
355318

356-
### 2. How do I customize a whitelist for `SanitizationFilter`s?
357-
358-
`SanitizationFilter::WHITELIST` is the default whitelist used if no `:whitelist`
359-
argument is given in the context. The default is a good starting template for
360-
you to add additional elements. You can either modify the constant's value, or
361-
re-define your own constant and pass that in via the context.
362-
363319
## Contributing
364320

365-
Please review the [Contributing Guide](https://github.com/jch/html-pipeline/blob/master/CONTRIBUTING.md).
366-
367-
1. [Fork it](https://help.github.com/articles/fork-a-repo)
368-
2. Create your feature branch (`git checkout -b my-new-feature`)
369-
3. Commit your changes (`git commit -am 'Added some feature'`)
370-
4. Push to the branch (`git push origin my-new-feature`)
371-
5. Create new [Pull Request](https://help.github.com/articles/using-pull-requests)
372-
373-
To see what has changed in recent versions, see the [CHANGELOG](https://github.com/jch/html-pipeline/blob/master/CHANGELOG.md).
374-
375321
### Contributors
376322

377-
Thanks to all of [these contributors](https://github.com/jch/html-pipeline/graphs/contributors).
378-
379-
Project is a member of the [OSS Manifesto](http://ossmanifesto.org/).
380-
381-
### Releasing A New Version
382-
383-
This section is for gem maintainers to cut a new version of the gem.
384-
385-
* create a new branch named `release-x.y.z` where `x.y.z` follows [semver](http://semver.org)
386-
* update lib/html/pipeline/version.rb to next version number X.X.X
387-
* update CHANGELOG.md. Prepare a draft with `script/changelog`
388-
* push branch and create a new pull request
389-
* after tests are green, merge to master
390-
* on the master branch, run `script/release`
323+
Thanks to all of [these contributors](https://github.com/jch/html-pipeline/graphs/contributors), who have made the original gem possible.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module MotionHTMLPipeline
22
class Pipeline
3-
VERSION = '0.1'.freeze
3+
VERSION = '0.2'.freeze
44
end
55
end

0 commit comments

Comments
 (0)