motion-algolia-search 2.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/.gitignore +16 -0
- data/MotionAlgoliaSearch.gemspec +17 -0
- data/README.md +25 -0
- data/Rakefile +17 -0
- data/app/algolia_search_config.rb +3 -0
- data/app/app_delegate.rb +8 -0
- data/app/contact.rb +29 -0
- data/app/search_display.rb +19 -0
- data/app/search_view_controller.rb +76 -0
- data/lib/motion-algolia-search.rb +5 -0
- data/lib/motion-algolia-search/version.rb +3 -0
- data/lib/motion/project/motion-algolia-search.rb +61 -0
- data/resources/Default-568h@2x.png +0 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
data.tar.gz: 1a96438ce5383db590b627ce779a01660aece2e8237afee3df7fa0ec869a930d47f9e759fca1d27b3d2ec5ed9ac038aee1de2fadd4fcbbad50f4d98a2a3e9ee6
|
4
|
+
metadata.gz: 8610944362a42fc5e3bbde1ada0b2e9d624a6bd4668a88e97a9a110f43edeb6e475406014216d4e00d63f2c33e2a455a11ef4d8cbb76ae84284c1ca38aa76621
|
5
|
+
SHA1:
|
6
|
+
data.tar.gz: 3cdf7b614ef21d1654a503f4dc0053e81fac890b
|
7
|
+
metadata.gz: 13d23336fea5fc5c2262cf08077f612469f040ac
|
data/.gitignore
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/motion-algolia-search/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "motion-algolia-search"
|
6
|
+
s.version = MotionAlgoliaSearch::VERSION
|
7
|
+
s.authors = ["Joffrey Jaffeux"]
|
8
|
+
s.email = ["j.jaffeux@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/algolia/rubymotion"
|
10
|
+
s.summary = "A RubyMotion gem for Algolia Offline Search SDK"
|
11
|
+
s.description = "A RubyMotion gem for Algolia Offline Search SDK"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
|
16
|
+
s.add_development_dependency 'rake'
|
17
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Description
|
2
|
+
|
3
|
+
Simple integration of Algolia Offline Search SDK : http://www.algolia.com/ in your RubyMotion application.
|
4
|
+
|
5
|
+
|
6
|
+
# Installation
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'motion-algolia-search'
|
10
|
+
```
|
11
|
+
|
12
|
+
Donwload the SDK (http://www.algolia.com/get-started/) and put in your vendor directory, then update your Rakefile :
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
app.algolia_search.license = "YOUR KEY"
|
16
|
+
|
17
|
+
app.vendor_project('vendor/AlgoliaSearch.framework',
|
18
|
+
:static,
|
19
|
+
:products => %w{AlgoliaSearch},
|
20
|
+
:headers_dir => 'Headers')
|
21
|
+
```
|
22
|
+
|
23
|
+
# Example
|
24
|
+
|
25
|
+
See in app folder.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
3
|
+
require 'motion/project'
|
4
|
+
|
5
|
+
$:.unshift("./lib/")
|
6
|
+
require './lib/motion/project/motion-algolia-search'
|
7
|
+
|
8
|
+
Motion::Project::App.setup do |app|
|
9
|
+
# Use `rake config' to see complete project settings.
|
10
|
+
app.name = 'motion-algolia-search'
|
11
|
+
app.algolia_search.license = "YOUR KEY"
|
12
|
+
|
13
|
+
app.vendor_project('vendor/AlgoliaSearch.framework',
|
14
|
+
:static,
|
15
|
+
:products => %w{AlgoliaSearch},
|
16
|
+
:headers_dir => 'Headers')
|
17
|
+
end
|
data/app/app_delegate.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
class AppDelegate
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
3
|
+
window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
4
|
+
window.rootViewController = SearchViewController.alloc.init
|
5
|
+
window.makeKeyAndVisible
|
6
|
+
true
|
7
|
+
end
|
8
|
+
end
|
data/app/contact.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class Contact < NSObject
|
2
|
+
attr_accessor :name
|
3
|
+
attr_accessor :company
|
4
|
+
|
5
|
+
def initWithName(name, andCompany:company)
|
6
|
+
self.init
|
7
|
+
@name = name
|
8
|
+
@company = company
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def serialize(writer)
|
13
|
+
writer.writeString(@name)
|
14
|
+
writer.writeString(@company)
|
15
|
+
end
|
16
|
+
|
17
|
+
def deserialize(reader, classVersion:version)
|
18
|
+
@name = reader.readString
|
19
|
+
@company = reader.readString
|
20
|
+
end
|
21
|
+
|
22
|
+
def getUID
|
23
|
+
@name
|
24
|
+
end
|
25
|
+
|
26
|
+
def textToIndex
|
27
|
+
[@name]
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SearchDisplay
|
2
|
+
|
3
|
+
def add_search_display
|
4
|
+
@search_bar = UISearchBar.alloc.initWithFrame([[0,0],[320,50]])
|
5
|
+
@search_bar.delegate = self
|
6
|
+
@search_bar.autocorrectionType = UITextAutocorrectionTypeNo
|
7
|
+
@search_bar.autocapitalizationType = UITextAutocapitalizationTypeNone
|
8
|
+
self.view.addSubview(@search_bar)
|
9
|
+
|
10
|
+
@search_display = UISearchDisplayController.alloc.initWithSearchBar(@search_bar, contentsController:self)
|
11
|
+
@search_display.delegate = self
|
12
|
+
@search_display.searchResultsDataSource = self
|
13
|
+
@search_display.searchResultsDelegate = self
|
14
|
+
@search_display.setActive(true, animated:true)
|
15
|
+
|
16
|
+
@search_bar.becomeFirstResponder
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
class SearchViewController < UIViewController
|
2
|
+
include SearchDisplay
|
3
|
+
|
4
|
+
# based on http://www.algolia.com/doc/ios2/#iOS_SearcObjectsAttributes
|
5
|
+
def viewDidLoad
|
6
|
+
super
|
7
|
+
self.view.backgroundColor = UIColor.whiteColor
|
8
|
+
self.add_search_display # boilerplate code, non related to algolia
|
9
|
+
|
10
|
+
# Index creation
|
11
|
+
@suggestions = nil
|
12
|
+
@as_index = ASIndex.alloc.initWithName("QuickStart", delegate:self, userDataClass:Contact)
|
13
|
+
|
14
|
+
# Indexation
|
15
|
+
# Each entry is a Cotact object defined in contact.rb
|
16
|
+
unless ASIndex.indexExists("QuickStart")
|
17
|
+
@as_index.setEntry(Contact.alloc.initWithName("Kate Bell", andCompany:"Creative Consulting"))
|
18
|
+
@as_index.setEntry(Contact.alloc.initWithName("Anna Haro", andCompany:"Apple Inc"))
|
19
|
+
@as_index.setEntry(Contact.alloc.initWithName("Anna Bell", andCompany:"Turba Corp"))
|
20
|
+
@as_index.publishChanges
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def searchBar(search_bar, textDidChange:search_text)
|
25
|
+
# Search query in the index
|
26
|
+
@as_index.asyncSearch(ASSearchQuery.queryWithString(search_text))
|
27
|
+
end
|
28
|
+
|
29
|
+
def didSearch(index, result:result, query:query)
|
30
|
+
@suggestions = result
|
31
|
+
# Reload tableView based on results
|
32
|
+
@search_display.searchResultsTableView.reloadData
|
33
|
+
end
|
34
|
+
|
35
|
+
def tableView(tableView, cellForRowAtIndexPath:indexPath)
|
36
|
+
@reuseIdentifier ||= 'ALGOLIASEARCHCELL'
|
37
|
+
|
38
|
+
cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier)
|
39
|
+
if cell.nil?
|
40
|
+
cell = UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:@reuseIdentifier)
|
41
|
+
|
42
|
+
name_label = ASUILabel.alloc.initWithFrame([[10, 5], [cell.frame.size.width - 20, cell.frame.size.height - 20]])
|
43
|
+
name_label.tag = 42
|
44
|
+
name_label.font = UIFont.fontWithName("Helvetica-Bold", size:20)
|
45
|
+
name_label.backgroundColor = UIColor.clearColor
|
46
|
+
name_label.textColor = UIColor.blackColor
|
47
|
+
cell.contentView.addSubview(name_label)
|
48
|
+
|
49
|
+
company_label = ASUILabel.alloc.initWithFrame([[10, cell.frame.size.height - 20],[cell.frame.size.width - 20, 20]])
|
50
|
+
company_label.tag = 43
|
51
|
+
company_label.font = UIFont.fontWithName("Helvetica", size:14)
|
52
|
+
company_label.backgroundColor = UIColor.clearColor
|
53
|
+
company_label.textColor = UIColor.blackColor
|
54
|
+
cell.contentView.addSubview(company_label)
|
55
|
+
|
56
|
+
cell.accessoryType = UITableViewCellAccessoryNone
|
57
|
+
end
|
58
|
+
|
59
|
+
hit = @suggestions.hits[indexPath.row]
|
60
|
+
contact = hit.userData
|
61
|
+
name_label = cell.viewWithTag(42)
|
62
|
+
company_label = cell.viewWithTag(43)
|
63
|
+
|
64
|
+
#highlight letters of the results
|
65
|
+
name_label.text = @as_index.highlight(contact.name, withHit:hit).highlightedText
|
66
|
+
company_label.text = contact.company
|
67
|
+
|
68
|
+
cell
|
69
|
+
end
|
70
|
+
|
71
|
+
# update number of rows when reloading tableView
|
72
|
+
def tableView(tableView, numberOfRowsInSection:section)
|
73
|
+
@suggestions.nil? ? 0 : @suggestions.hits.count
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
class AlgoliaSearchConfig
|
6
|
+
attr_accessor :license
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def license=(license)
|
13
|
+
@license = license
|
14
|
+
create_code
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def create_code
|
20
|
+
unless @license
|
21
|
+
raise "Need to configure `app.algolia_search.license' variable"
|
22
|
+
end
|
23
|
+
|
24
|
+
code = <<EOF
|
25
|
+
# AlgoliaSearch SDK launcher
|
26
|
+
# This file is automatically generated. Do not edit.
|
27
|
+
ASIndex.initLibWithLicenseKey("#{@license}")
|
28
|
+
EOF
|
29
|
+
|
30
|
+
algolia_search_file = './app/algolia_search_config.rb'
|
31
|
+
create_stub(algolia_search_file, code)
|
32
|
+
add_file(algolia_search_file)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_stub(path, code)
|
36
|
+
if !File.exist?(path) or File.read(path) != code
|
37
|
+
File.open(path, 'w') { |io| io.write(code) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_file(path)
|
42
|
+
files = @config.files.flatten
|
43
|
+
@config.files << path unless files.find { |x| File.expand_path(x) == File.expand_path(path) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Motion
|
48
|
+
module Project
|
49
|
+
class Config
|
50
|
+
|
51
|
+
variable :algolia_search
|
52
|
+
|
53
|
+
def algolia_search
|
54
|
+
@algolia_search ||= AlgoliaSearchConfig.new(self)
|
55
|
+
yield @algolia_search if block_given?
|
56
|
+
@algolia_search
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-algolia-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joffrey Jaffeux
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2013-04-16 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
prerelease: false
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- &id002
|
20
|
+
- ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :development
|
24
|
+
version_requirements: *id001
|
25
|
+
description: A RubyMotion gem for Algolia Offline Search SDK
|
26
|
+
email:
|
27
|
+
- j.jaffeux@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- MotionAlgoliaSearch.gemspec
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- app/algolia_search_config.rb
|
40
|
+
- app/app_delegate.rb
|
41
|
+
- app/contact.rb
|
42
|
+
- app/search_display.rb
|
43
|
+
- app/search_view_controller.rb
|
44
|
+
- lib/motion-algolia-search.rb
|
45
|
+
- lib/motion-algolia-search/version.rb
|
46
|
+
- lib/motion/project/motion-algolia-search.rb
|
47
|
+
- resources/Default-568h@2x.png
|
48
|
+
homepage: https://github.com/algolia/rubymotion
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
metadata: {}
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- *id002
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- *id002
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.0.3
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: A RubyMotion gem for Algolia Offline Search SDK
|
71
|
+
test_files: []
|
72
|
+
|