motion-html 1.0.0
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 +7 -0
- data/README.md +52 -0
- data/lib/motion-html.rb +15 -0
- data/lib/project/motion-html.rb +24 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 392fefe378577b425c273a9ac686f125c2dd4d8f
|
4
|
+
data.tar.gz: c59f65adb0fbc10124b00f2c8e6aeba41c59c497
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a68e6b595ff00ccb1ab489a275892365a7964503a91e789f5752087637eece24f1122b57f7f13e643a2cd134b9688f959b85524ed9f76f793c3a2b24b67c9b47
|
7
|
+
data.tar.gz: b35b9cca53ae1bc3c05ed5b7c91b9f0cef5a0acee88a64009a9a0c3ba481c0e326c0df0912b059b11d4f4355d0d23be221efd18ad1a77fc075263c1e7b84097d
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# motion-html
|
2
|
+
|
3
|
+
Motion::HTML lets you parse and traverse HTML in your RubyMotion app. It's like Nokogiri for RubyMotion.
|
4
|
+
|
5
|
+
Motion::HTML uses [IGHTMLQuery](https://github.com/siuying/IGHTMLQuery) under the hood.
|
6
|
+
|
7
|
+
Currently, only iOS is supported.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'motion-html'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle && rake pod:install
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Initialize a new document:
|
22
|
+
```ruby
|
23
|
+
doc = Motion::HTML::Doc.new(html)
|
24
|
+
# or simply:
|
25
|
+
doc = Motion::HTML.parse(html)
|
26
|
+
```
|
27
|
+
|
28
|
+
Then query using css or xpath selectors. It returns an array of nodes:
|
29
|
+
```ruby
|
30
|
+
nodes = doc.query('.photos li a')
|
31
|
+
```
|
32
|
+
|
33
|
+
# Iterate over the results, and use the attributes or content:
|
34
|
+
```ruby
|
35
|
+
nodes.each do |node|
|
36
|
+
puts "Link text: " + node.text
|
37
|
+
puts "Link URL: " + node['href']
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
So far, these are the only features that I have needed. Feel free to submit a GitHub issue if you need anything else.
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
50
|
+
|
51
|
+
## License
|
52
|
+
MIT
|
data/lib/motion-html.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
unless defined?(Motion::Project::Config)
|
4
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
5
|
+
end
|
6
|
+
|
7
|
+
require "motion-cocoapods"
|
8
|
+
|
9
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
10
|
+
Motion::Project::App.setup do |app|
|
11
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
|
12
|
+
app.pods do
|
13
|
+
pod "IGHTMLQuery", "~> 0.8.4"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Motion
|
2
|
+
module HTML
|
3
|
+
def self.parse(html)
|
4
|
+
Doc.new(html)
|
5
|
+
end
|
6
|
+
|
7
|
+
class Doc
|
8
|
+
def initialize(html)
|
9
|
+
@doc = IGHTMLDocument.alloc.initWithHTMLString(html, error: nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
def query(q)
|
13
|
+
if q =~ %r{^[//|/]}
|
14
|
+
node_set = @doc.queryWithXPath(q)
|
15
|
+
else
|
16
|
+
node_set = @doc.queryWithCSS(q)
|
17
|
+
end
|
18
|
+
nodes = []
|
19
|
+
node_set.enumerateNodesUsingBlock -> (node, index, stop) { nodes << node }
|
20
|
+
nodes
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Havens
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: motion-cocoapods
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Parse and traverse HTML in your RubyMotion app. It's like Nokogiri for
|
42
|
+
RubyMotion!
|
43
|
+
email:
|
44
|
+
- email@andrewhavens.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- README.md
|
50
|
+
- lib/motion-html.rb
|
51
|
+
- lib/project/motion-html.rb
|
52
|
+
homepage: https://github.com/andrewhavens/motion-html
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.5.1
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Parse and traverse HTML in your RubyMotion app. It's like Nokogiri for RubyMotion!
|
76
|
+
test_files: []
|