motion-html-pipeline 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91205fa1d79198a224c28464e12946d1294ac518124dec20b536e86d77d91a49
4
- data.tar.gz: 6388828a786942a593664a2759daec71b61582d283a692ffcd0c5d5b1f9f70d3
3
+ metadata.gz: 55c54e232963c7cf35b570d08254c1e606734fdfa9366b283a725ca000b93e27
4
+ data.tar.gz: 88cc47077bb6987d072abd324721d5c31ec06d6ac24a4a829fdcc7bd860faa2b
5
5
  SHA512:
6
- metadata.gz: 12a542cb6b5380268836031a1cfabde939bd32dc3bdb9b71ace8060a97f9c1e170d49ed88c06f79e64e62350eb09b68ec7e10952a21e2547d6c5d8d7db28a10c
7
- data.tar.gz: 86091ee0ccca5c6e97ec59a04aca17e23f66a56ab28c5f696d4fd8f6145a021cb946d5e216d321cd28bede723e6df773565387313c4b274fb607504d661eda8b
6
+ metadata.gz: 9a0826f7b29520d89e95ceb4c29ebf14c4e6d6a9c545ffccff10e36d8dab55a4bbb395f1b3a05bb322eac611589c0b5b44a59abdca439b803be26bcca1136481
7
+ data.tar.gz: 455fda735e854253104bc9562bb6e6b06ce56fd9c598577356ac2d38b353d15e3b8aa63ff1cfbd0b228a5e58c42f0a30d178ac8afcad5e142e4058aa044c6e5d
data/README.md CHANGED
@@ -3,16 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/motion-html-pipeline.svg)](http://badge.fury.io/rb/motion-html-pipeline)
4
4
  [![Build Status](https://travis-ci.org/digitalmoksha/motion-html-pipeline.svg?branch=master)](https://travis-ci.org/digitalmoksha/motion-html-pipeline)
5
5
 
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
- ---
15
- # 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)_
16
7
 
17
8
  GitHub HTML processing filters and utilities. This module includes a small
18
9
  framework for defining DOM based content filters and applying them to user
@@ -23,95 +14,93 @@ provided content. Read an introduction about this project in
23
14
  - [Usage](#usage)
24
15
  - [Examples](#examples)
25
16
  - [Filters](#filters)
26
- - [Dependencies](#dependencies)
17
+ - [Disabled Filters](#disabled-filters)
27
18
  - [Documentation](#documentation)
28
19
  - [Extending](#extending)
29
20
  - [3rd Party Extensions](#3rd-party-extensions)
30
21
  - [Instrumenting](#instrumenting)
31
22
  - [Contributing](#contributing)
32
23
  - [Contributors](#contributors)
33
- - [Releasing A New Version](#releasing-a-new-version)
34
24
 
35
25
  ## Installation
36
26
 
37
27
  Add this line to your application's Gemfile:
38
28
 
39
29
  ```ruby
40
- gem 'html-pipeline'
30
+ gem 'motion-html-pipeline'
41
31
  ```
42
32
 
43
- And then execute:
33
+ and to your `Rakefile`
44
34
 
45
- ```sh
46
- $ bundle
35
+ ```ruby
36
+ require 'motion-html-pipeline'
47
37
  ```
48
38
 
49
- Or install it yourself as:
39
+ And then execute:
50
40
 
51
41
  ```sh
52
- $ gem install html-pipeline
42
+ $ bundle
53
43
  ```
54
44
 
55
45
  ## Usage
56
46
 
57
- This library provides a handful of chainable HTML filters to transform user
58
- content into markup. A filter takes an HTML string or
59
- `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
60
50
  outputs the result.
61
51
 
62
- For example, to transform Markdown source into Markdown HTML:
52
+ For example, to transform an image URL into an image tag:
63
53
 
64
54
  ```ruby
65
- require 'html/pipeline'
66
-
67
- filter = HTML::Pipeline::MarkdownFilter.new("Hi **world**!")
55
+ filter = MotionHTMLPipeline::Pipeline::ImageFilter.new("http://example.com/test.jpg")
68
56
  filter.call
69
57
  ```
70
58
 
59
+ would output
60
+
61
+ ```html
62
+ <img src="http://example.com/test.jpg" alt=""/>
63
+ ```
64
+
71
65
  Filters can be combined into a pipeline which causes each filter to hand its
72
66
  output to the next filter's input. So if you wanted to have content be
73
- filtered through Markdown and be syntax highlighted, you can create the
74
- following pipeline:
67
+ filtered through the `ImageFilter` and then wrap it in an `<a>` tag with
68
+ a max-width inline style:
75
69
 
76
70
  ```ruby
77
- pipeline = HTML::Pipeline.new [
78
- HTML::Pipeline::MarkdownFilter,
79
- HTML::Pipeline::SyntaxHighlightFilter
80
- ]
81
- result = pipeline.call <<-CODE
82
- This is *great*:
83
-
84
- some_code(:first)
85
-
86
- CODE
71
+ pipeline = MotionHTMLPipeline::Pipeline.new([
72
+ MotionHTMLPipeline::Pipeline::ImageFilter,
73
+ MotionHTMLPipeline::Pipeline::ImageMaxWidthFilter
74
+ ])
75
+ result = pipeline.call("http://example.com/test.jpg")
87
76
  result[:output].to_s
88
77
  ```
89
78
 
90
79
  Prints:
91
80
 
92
81
  ```html
93
- <p>This is <em>great</em>:</p>
94
-
95
- <pre><code>some_code(:first)
96
- </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>
97
83
  ```
98
84
 
99
- 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`.
100
-
101
85
  Some filters take an optional **context** and/or **result** hash. These are
102
86
  used to pass around arguments and metadata between filters in a pipeline. For
103
- example, if you don't want to use GitHub formatted Markdown, you can pass an
104
- option in the context hash:
87
+ example, with the `AbsoluteSourceFilter` you can pass in `:image_base_url` in
88
+ the context hash:
89
+
105
90
 
106
91
  ```ruby
107
- 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')
108
93
  filter.call
109
94
  ```
110
95
 
111
96
  ### Examples
112
97
 
113
98
  We define different pipelines for different parts of our app. Here are a few
114
- 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._
115
104
 
116
105
  ```ruby
117
106
  # The context hash is how you pass options between different filters.
@@ -166,68 +155,51 @@ EmojiPipeline = Pipeline.new [
166
155
 
167
156
  ## Filters
168
157
 
169
- * `MentionFilter` - replace `@user` mentions with links
170
158
  * `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
171
167
  * `AutolinkFilter` - auto_linking urls in HTML
172
168
  * `CamoFilter` - replace http image urls with [camo-fied](https://github.com/atmos/camo) https versions
173
169
  * `EmailReplyFilter` - util filter for working with emails
174
170
  * `EmojiFilter` - everyone loves [emoji](http://www.emoji-cheat-sheet.com/)!
175
- * `HttpsFilter` - HTML Filter for replacing http github urls with https versions.
176
- * `ImageMaxWidthFilter` - link to full size image for large images
177
171
  * `MarkdownFilter` - convert markdown to html
178
172
  * `PlainTextInputFilter` - html escape text and wrap the result in a div
179
173
  * `SanitizationFilter` - whitelist sanitize user markup
180
174
  * `SyntaxHighlightFilter` - code syntax highlighter
181
- * `TextileFilter` - convert textile to html
182
175
  * `TableOfContentsFilter` - anchor headings with name attributes and generate Table of Contents html unordered list linking headings
183
176
 
184
- ## Dependencies
185
-
186
- Filter gem dependencies are not bundled; you must bundle the filter's gem
187
- dependencies. The below list details filters with dependencies. For example,
188
- `SyntaxHighlightFilter` uses [rouge](https://github.com/jneen/rouge)
189
- to detect and highlight languages. For example, to use the `SyntaxHighlightFilter`,
190
- add the following to your Gemfile:
191
-
192
- ```ruby
193
- gem 'rouge'
194
- ```
195
-
196
- * `AutolinkFilter` - `rinku`
197
- * `EmailReplyFilter` - `escape_utils`, `email_reply_parser`
198
- * `EmojiFilter` - `gemoji`
199
- * `MarkdownFilter` - `commonmarker`
200
- * `PlainTextInputFilter` - `escape_utils`
201
- * `SanitizationFilter` - `sanitize`
202
- * `SyntaxHighlightFilter` - `rouge`
203
- * `TableOfContentsFilter` - `escape_utils`
204
- * `TextileFilter` - `RedCloth`
205
-
206
- _Note:_ See [Gemfile](/Gemfile) `:test` block for version requirements.
207
-
208
177
  ## Documentation
209
178
 
210
- 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).
211
180
 
212
181
  ## Extending
182
+
213
183
  To write a custom filter, you need a class with a `call` method that inherits
214
- from `HTML::Pipeline::Filter`.
184
+ from `MotionHTMLPipeline::Pipeline::Filter`.
215
185
 
216
186
  For example this filter adds a base url to images that are root relative:
217
187
 
218
188
  ```ruby
219
- require 'uri'
220
-
221
- class RootRelativeFilter < HTML::Pipeline::Filter
189
+ class RootRelativeFilter < MotionHTMLPipeline::Pipeline::Filter
222
190
 
223
191
  def call
224
- doc.search("img").each do |img|
192
+ doc.css("img").each do |img|
225
193
  next if img['src'].nil?
194
+
226
195
  src = img['src'].strip
196
+
227
197
  if src.start_with? '/'
228
- 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
229
200
  end
230
201
  end
202
+
231
203
  doc
232
204
  end
233
205
 
@@ -237,15 +209,14 @@ end
237
209
  Now this filter can be used in a pipeline:
238
210
 
239
211
  ```ruby
240
- Pipeline.new [ RootRelativeFilter ], { :base_url => 'http://somehost.com' }
212
+ Pipeline.new [ RootRelativeFilter ], { base_url: 'http://somehost.com' }
241
213
  ```
242
214
 
215
+ We use [HTMLKit](https://github.com/iabudiab/HTMLKit) for document parsing in `MotionHTMLPipeline::DocumentFragment`.
216
+
243
217
  ### 3rd Party Extensions
244
218
 
245
- If you have an idea for a filter, propose it as
246
- [an issue](https://github.com/jch/html-pipeline/issues) first. This allows us discuss
247
- whether the filter is a common enough use case to belong in this gem, or should be
248
- built as an external gem.
219
+ 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.
249
220
 
250
221
  Here are some extensions people have built:
251
222
 
@@ -271,22 +242,25 @@ Here are some extensions people have built:
271
242
 
272
243
  ## Instrumenting
273
244
 
245
+ _Although instrumenting was ported, it has not been used real-world, and may not work
246
+ properly at this time._
247
+
274
248
  Filters and Pipelines can be set up to be instrumented when called. The pipeline
275
249
  must be setup with an
276
250
  [ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html)
277
251
  compatible service object and a name. New pipeline objects will default to the
278
- `HTML::Pipeline.default_instrumentation_service` object.
252
+ `MotionHTMLPipeline::Pipeline.default_instrumentation_service` object.
279
253
 
280
254
  ``` ruby
281
255
  # the AS::Notifications-compatible service object
282
256
  service = ActiveSupport::Notifications
283
257
 
284
258
  # instrument a specific pipeline
285
- pipeline = HTML::Pipeline.new [MarkdownFilter], context
259
+ pipeline = MotionHTMLPipeline::Pipeline.new [MarkdownFilter], context
286
260
  pipeline.setup_instrumentation "MarkdownPipeline", service
287
261
 
288
262
  # or set default instrumentation service for all new pipelines
289
- HTML::Pipeline.default_instrumentation_service = service
263
+ MotionHTMLPipeline::Pipeline.default_instrumentation_service = service
290
264
  pipeline = HTML::Pipeline.new [MarkdownFilter], context
291
265
  pipeline.setup_instrumentation "MarkdownPipeline"
292
266
  ```
@@ -321,6 +295,8 @@ end
321
295
 
322
296
  ## FAQ
323
297
 
298
+ _I have left this FAQ item here for when we get the `PlainTextInputFilter` working._
299
+
324
300
  ### 1. Why doesn't my pipeline work when there's no root element in the document?
325
301
 
326
302
  To make a pipeline work on a plain text document, put the `PlainTextInputFilter`
@@ -342,38 +318,8 @@ html_fragment = "This is outside of an html element, but <strong>this isn't. :+1
342
318
  EmojiPipeline.call("<div>#{html_fragment}</div>") # <- Wrap your own html fragments to avoid escaping
343
319
  ```
344
320
 
345
- ### 2. How do I customize a whitelist for `SanitizationFilter`s?
346
-
347
- `SanitizationFilter::WHITELIST` is the default whitelist used if no `:whitelist`
348
- argument is given in the context. The default is a good starting template for
349
- you to add additional elements. You can either modify the constant's value, or
350
- re-define your own constant and pass that in via the context.
351
-
352
321
  ## Contributing
353
322
 
354
- Please review the [Contributing Guide](https://github.com/jch/html-pipeline/blob/master/CONTRIBUTING.md).
355
-
356
- 1. [Fork it](https://help.github.com/articles/fork-a-repo)
357
- 2. Create your feature branch (`git checkout -b my-new-feature`)
358
- 3. Commit your changes (`git commit -am 'Added some feature'`)
359
- 4. Push to the branch (`git push origin my-new-feature`)
360
- 5. Create new [Pull Request](https://help.github.com/articles/using-pull-requests)
361
-
362
- To see what has changed in recent versions, see the [CHANGELOG](https://github.com/jch/html-pipeline/blob/master/CHANGELOG.md).
363
-
364
323
  ### Contributors
365
324
 
366
- Thanks to all of [these contributors](https://github.com/jch/html-pipeline/graphs/contributors).
367
-
368
- Project is a member of the [OSS Manifesto](http://ossmanifesto.org/).
369
-
370
- ### Releasing A New Version
371
-
372
- This section is for gem maintainers to cut a new version of the gem.
373
-
374
- * create a new branch named `release-x.y.z` where `x.y.z` follows [semver](http://semver.org)
375
- * update lib/html/pipeline/version.rb to next version number X.X.X
376
- * update CHANGELOG.md. Prepare a draft with `script/changelog`
377
- * push branch and create a new pull request
378
- * after tests are green, merge to master
379
- * on the master branch, run `script/release`
325
+ Thanks to all of [these contributors](https://github.com/jch/html-pipeline/graphs/contributors), who have made the original gem possible.
@@ -4,7 +4,7 @@
4
4
  # Not meant to duplicate Nokogiri completely, just add a similar interface
5
5
  #------------------------------------------------------------------------------
6
6
  module MotionHTMLPipeline
7
- class DocumentFragment < HTMLDocument
7
+ class DocumentFragment
8
8
  attr_reader :document
9
9
 
10
10
  def self.parse(html)
@@ -1,5 +1,5 @@
1
1
  module MotionHTMLPipeline
2
2
  class Pipeline
3
- VERSION = '0.1'.freeze
3
+ VERSION = '0.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-html-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-07-07 00:00:00.000000000 Z
14
+ date: 2019-07-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: motion-cocoapods