JRank 0.1.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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in JRank.gemspec
4
+ gemspec
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "JRank/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "JRank"
7
+ s.version = Jrank::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Paul Ketelle & Dave Almond"]
10
+ s.email = ["paul@ketelle.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{JRank search gem for rails}
13
+ s.description = %q{Adds easy to use JRank search to any website}
14
+
15
+ s.rubyforge_project = "Jrank"
16
+
17
+ s.add_dependency 'xml-object'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,40 @@
1
+ = JRank
2
+
3
+ JRank.org search engine plugin
4
+
5
+ == Install
6
+
7
+ === JRank.org
8
+
9
+ Go to Jrank.org and create an account and setup your site. Making note of the sites apikey.
10
+
11
+ === Rails 3
12
+
13
+ You can let bundler install JRank by adding this line to your application's Gemfile:
14
+
15
+ gem 'jrank'
16
+
17
+ And then execute:
18
+
19
+ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ gem install jrank
24
+
25
+ Then run jrank install
26
+
27
+ rails g jrank:install
28
+
29
+ == Usage
30
+
31
+ Edit the file config/jrank.yml:
32
+
33
+ development:
34
+ jrank_apikey: apikey_here
35
+
36
+ test:
37
+ ...
38
+
39
+ production:
40
+ ...
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+
2
+ class Jrank::SearchController < ApplicationController
3
+
4
+ unloadable
5
+
6
+ def index
7
+ if !params[:query].blank?
8
+ @jrank = Jrank::Search.new.find(params[:query], params[:start] ||= "0", params[:limit] ||= "10")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Jrank::SearchHelper
2
+ def html_render(str)
3
+ str.gsub('&amp;', '&').gsub('&lt;', '<').gsub('&gt;', '>').html_safe
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ <form method="get" action="<%= jrank_search_path %>" class="jrank_form">
2
+ <%= field_set_tag "Search Form" do %>
3
+ <%= label_tag "query", "Search" %>
4
+ <%= search_field_tag "query" %>
5
+ <input type="submit" value="Submit" />
6
+ <% end %>
7
+ </form>
@@ -0,0 +1,16 @@
1
+ <% if total_pages.to_i > 1 %>
2
+ <ul class="jrank_paging">
3
+ <% pages.each do |page| %>
4
+ <li>
5
+ <% unless page.number == current_page or html_render(page.number) == "&hellip;" %>
6
+ <%= link_to (page.number.to_i+1), params.merge( :start => page.start ) %>
7
+ <% else %>
8
+ <span>
9
+ <%= page.number.to_i+1 if html_render(page.number) != "&hellip;" && page.number == current_page%>
10
+ <%= html_render(page.number) if html_render(page.number) == "&hellip;" %>
11
+ </span>
12
+ <% end %>
13
+ </li>
14
+ <% end %>
15
+ </ul>
16
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <li>
2
+ <h3><%= html_render(entry.title) %></h3>
3
+ <p><%= html_render(entry.content) %></p>
4
+ <p><%= link_to entry.url, entry.url %></p>
5
+ </li>
@@ -0,0 +1,9 @@
1
+ <ul class="jrank_entries">
2
+ <% if total > "0" %>
3
+ <% entries.each do |entry| %>
4
+ <%= render "result", :entry => entry %>
5
+ <% end %>
6
+ <% else %>
7
+ <li>No results found for <%= query %></li>
8
+ <% end %>
9
+ </ul>
@@ -0,0 +1,15 @@
1
+ <h1>JRank Site Search</h1>
2
+
3
+ <%= render "form" %>
4
+
5
+ <% unless @jrank.nil? %>
6
+ <h2>Results for "<%= @jrank.meta.query %>"</h2>
7
+ <%= render "results", :entries => @jrank.entries, :total => @jrank.meta.total, :query => @jrank.meta.query %>
8
+
9
+ <%= render "paging", :pages => @jrank.pages, :current_page => @jrank.meta.current_page, :total_pages => @jrank.meta.total_pages %>
10
+ <% end %>
11
+ <p>
12
+ <a style="display:inline-block" href="http://www.jrank.org/">
13
+ <img alt="Site Search" src="http://www.jrank.org/images/jrank_88_31-fs8.png" title="JRank Site Search">
14
+ </a>
15
+ </p>
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do |map|
2
+ match "search", :controller => 'jrank/search', :action => "index", :as => "jrank_search"
3
+ end
@@ -0,0 +1,33 @@
1
+ Feature: JRank submits a search
2
+
3
+ In Order to Receive JRank.org XML-Object
4
+ As a User
5
+ I want to submit search parameters
6
+
7
+ Scenario: submit search
8
+ Given I have a query of "swift"
9
+ When I submit a search
10
+ Then I should have an xml object
11
+
12
+ Scenario: no results returned
13
+ Given I have a query of ""
14
+ When I submit a search
15
+ Then I should have an xml object
16
+ And the xml has no results
17
+
18
+ Scenario: goto page 3
19
+ Given I have a query of "swift"
20
+ And I have a start value of "20"
21
+ When I submit a search
22
+ Then I should have an xml object
23
+ And the xml current page is "2"
24
+
25
+ Scenario: return 50 results per page
26
+ Given I have a query of "swift"
27
+ And I have a limit value of "50"
28
+ When I submit a search
29
+ Then I should have an xml object
30
+ And the xml page limit is "50"
31
+
32
+
33
+
@@ -0,0 +1,64 @@
1
+ Given "I have a rails application" do
2
+ steps %{
3
+ Given I generate a rails application
4
+ And this plugin is available
5
+ And I turn off class caching
6
+ And the rails application is prepped and running
7
+ }
8
+ end
9
+
10
+ Given %r{I generate a rails application} do
11
+ FileUtils.rm_rf TEMP_ROOT
12
+ FileUtils.mkdir_p TEMP_ROOT
13
+ Dir.chdir(TEMP_ROOT) do
14
+ `rails _3.0.9_ #{APP_NAME}`
15
+ end
16
+ end
17
+
18
+ When %r{I save the following as "([^"]*)"} do |path, string|
19
+ FileUtils.mkdir_p(File.join(CUC_RAILS_ROOT, File.dirname(path)))
20
+ File.open(File.join(CUC_RAILS_ROOT, path), 'w') { |file| file.write(string) }
21
+ end
22
+
23
+ When %r{I turn off class caching} do
24
+ Dir.chdir(CUC_RAILS_ROOT) do
25
+ file = "config/environments/test.rb"
26
+ config = IO.read(file)
27
+ config.gsub!(%r{^\s*config.cache_classes.*$},
28
+ "config.cache_classes = false")
29
+ File.open(file, "w"){|f| f.write(config) }
30
+ end
31
+ end
32
+
33
+ When %r{the rails application is prepped and running$} do
34
+ When "I reset the database"
35
+ When "the rails application is running"
36
+ end
37
+
38
+ When %r{I reset the database} do
39
+ When %{I run "rake db:drop db:create db:migrate"}
40
+ end
41
+
42
+ When %r{the rails application is running} do
43
+ Dir.chdir(CUC_RAILS_ROOT) do
44
+ require "config/environment"
45
+ require "capybara/rails"
46
+ end
47
+ end
48
+
49
+ When %r{this plugin is available} do
50
+ $LOAD_PATH << "#{PROJECT_ROOT}/lib"
51
+ require 'jrank'
52
+ When %{I save the following as "vendor/plugins/jrank/rails/init.rb"},
53
+ IO.read("#{PROJECT_ROOT}/rails/init.rb")
54
+ end
55
+
56
+ When %r{I run "([^"]*)"} do |command|
57
+ Dir.chdir(CUC_RAILS_ROOT) do
58
+ `#{command}`
59
+ end
60
+ end
61
+
62
+ When %r{I have a "([^"]*)" resource with "([^"]*)"} do |resource, fields|
63
+ When %{I run "script/generate scaffold #{resource} #{fields}"}
64
+ end
@@ -0,0 +1,41 @@
1
+
2
+ def limit
3
+ @limit ||= 10
4
+ end
5
+
6
+ def start
7
+ @start ||= 0
8
+ end
9
+
10
+ Given /^I have a query of "([^"]*)"$/ do |query|
11
+ @query = query
12
+ end
13
+
14
+ Given /^I have a start value of "([^"]*)"$/ do |start|
15
+ @start = start
16
+ end
17
+
18
+ Given /^I have a limit value of "([^"]*)"$/ do |limit|
19
+ @limit = limit
20
+ end
21
+
22
+ When /^I submit a search$/ do
23
+ jrank_search = Jrank::Search.new
24
+ @search_results = jrank_search.find(@query, start, limit)
25
+ end
26
+
27
+ Then /^I should have an xml object$/ do
28
+ @search_results.meta.total != nil
29
+ end
30
+
31
+ Then /^the xml has no results$/ do
32
+ @search_results.entries.should == ""
33
+ end
34
+
35
+ Then /^the xml current page is "([^"]*)"$/ do |current_page|
36
+ @search_results.meta.current_page.should == current_page
37
+ end
38
+
39
+ Then /^the xml page limit is "([^"]*)"$/ do |limit|
40
+ @search_results.meta.limit.should == limit
41
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
2
+ require 'Jrank'
@@ -0,0 +1 @@
1
+ require 'jrank/engine' if defined?(Rails)
@@ -0,0 +1,12 @@
1
+
2
+ require 'rails'
3
+ require 'jrank/search'
4
+
5
+ module Jrank
6
+ class Engine < Rails::Engine
7
+ initializer "add stylesheet" do |app|
8
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
9
+ ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :jrank => ["_jrank"]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ require 'xml-object'
2
+ require 'open-uri'
3
+ module Jrank
4
+ class Search
5
+
6
+ def initialize
7
+
8
+ end
9
+
10
+ def find(query, start = "0", limit = "10")
11
+ XMLObject.new(open("http://www.jrank.org/api/search/v2.xml?key=#{apikey}&q=#{URI.encode(query)}&start=#{URI.encode(start)}&limit=#{URI.encode(limit)}"))
12
+ end
13
+
14
+ def apikey
15
+ if File.exists?("#{Rails.root}/config/jrank.yml")
16
+ @apikey = (YAML.load_file("#{Rails.root}/config/jrank.yml")[Rails.env].symbolize_keys)[:jrank_apikey]
17
+ end
18
+ @apikey ||= ''
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Jrank
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails/generators'
2
+ module Jrank
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../../templates", __FILE__)
6
+
7
+ desc "Copies locale files to your application."
8
+
9
+ def copy_stylesheet
10
+ template "jrank.css", "public/stylesheets/jrank.css"
11
+ end
12
+
13
+ def copy_config
14
+ template "jrank.yml", "config/jrank.yml"
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ .jrank_entries {
2
+ list-style:none;
3
+ }
4
+ .jrank_paging {
5
+ margin-bottom:20px;
6
+ overflow:hidden;
7
+ }
8
+ .jrank_paging li{
9
+ float:left;
10
+ display:inline-block;
11
+ margin: 0 5px;
12
+ }
13
+
14
+ .jrank_paging li a, .jrank_paging li span {
15
+ display:block;
16
+ width:25px;
17
+ height:22px;
18
+ padding-top:3px;
19
+ border:1px solid #ccc;
20
+ text-align:center;
21
+ }
22
+ .jrank_form fieldset{
23
+ border:none;
24
+ }
25
+ .jrank_form legend {
26
+ display:none;
27
+ }
@@ -0,0 +1,8 @@
1
+ development:
2
+ jrank_apikey: [enter Jrank Api Key Here]
3
+
4
+ test:
5
+ jrank_apikey: [enter Jrank Api Key Here]
6
+
7
+ production:
8
+ jrank_apikey: [enter Jrank Api Key Here]
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: JRank
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paul Ketelle & Dave Almond
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-18 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: xml-object
16
+ requirement: &9739836 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *9739836
25
+ description: Adds easy to use JRank search to any website
26
+ email:
27
+ - paul@ketelle.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - JRank.gemspec
35
+ - README.rdoc
36
+ - Rakefile
37
+ - app/controllers/jrank/search_controller.rb
38
+ - app/helpers/jrank/search_helper.rb
39
+ - app/views/jrank/search/_form.html.erb
40
+ - app/views/jrank/search/_paging.html.erb
41
+ - app/views/jrank/search/_result.html.erb
42
+ - app/views/jrank/search/_results.html.erb
43
+ - app/views/jrank/search/index.html.erb
44
+ - config/routes.rb
45
+ - features/jrank_submits_search.feature
46
+ - features/step_definitions/rails_steps.rb
47
+ - features/step_definitions/search_steps.rb
48
+ - features/support/env.rb
49
+ - lib/JRank.rb
50
+ - lib/JRank/engine.rb
51
+ - lib/JRank/search.rb
52
+ - lib/JRank/version.rb
53
+ - lib/generators/jrank/install_generator.rb
54
+ - lib/generators/templates/jrank.css
55
+ - lib/generators/templates/jrank.yml
56
+ homepage: ''
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: Jrank
76
+ rubygems_version: 1.8.1
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: JRank search gem for rails
80
+ test_files: []