spud_search 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,27 @@
1
+ class SearchController < ApplicationController
2
+ layout Spud::Search.base_layout
3
+ require 'will_paginate/array'
4
+ def index
5
+ @results = []
6
+ if params[:phrase].blank?
7
+ return
8
+ end
9
+ @pages = []
10
+ @posts = []
11
+ begin
12
+ @pages = SpudPage.find_with_index(params[:phrase])
13
+ rescue
14
+ end
15
+
16
+ begin
17
+ @posts = SpudPost.find_with_index(params[:phrase])
18
+ rescue
19
+
20
+ end
21
+
22
+ @results += @pages
23
+ @results += @posts
24
+
25
+ @results = @results.paginate :page => params[:page]
26
+ end
27
+ end
@@ -0,0 +1,2 @@
1
+ module SearchHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::UsersHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::UserSessionsHelper
2
+ end
@@ -0,0 +1,21 @@
1
+ <h3>Search Results</h3>
2
+ <div class="results">
3
+ <%if @results.blank?%>
4
+ <p>No Results Found.</p>
5
+ <%else%>
6
+ <%@results.each do |result|%>
7
+ <div class="result">
8
+ <%if result.class.name == 'SpudPost'%>
9
+ <h4><%=link_to result.title,blog_post_path(result.url_name)%></h4>
10
+ <p><%=truncate(result.content,:length => 200, :separator => ' ')%></p>
11
+ <%elsif result.class.name == 'SpudPage'%>
12
+ <h4><%=link_to result.name,page_path(:id => result.url_name)%></h4>
13
+
14
+ <p><%=truncate(result.meta_description,:length => 200, :separator => ' ')%></p>
15
+
16
+ <%end%>
17
+ </div>
18
+ <%end%>
19
+ <%=will_paginate @results%>
20
+ <%end%>
21
+ </div>
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ if defined?(Bundler)
6
+ # If you precompile assets before deploying to production, use this line
7
+ Bundler.require *Rails.groups(:assets => %w(development test))
8
+ # If you want your assets lazily compiled in production, use this line
9
+ # Bundler.require(:default, :assets, Rails.env)
10
+ end
11
+
12
+ module Spud
13
+ module Search
14
+ class Application < Rails::Application
15
+ # Settings in config/environments/* take precedence over those specified here.
16
+ # Application configuration should go into files in config/initializers
17
+ # -- all .rb files in that directory are automatically loaded.
18
+
19
+ # Custom directories with classes and modules you want to be autoloadable.
20
+ # config.autoload_paths += %W(#{config.root}/extras)
21
+
22
+ # Only load the plugins named here, in the order given (default is alphabetical).
23
+ # :all can be used as a placeholder for all plugins not explicitly named.
24
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
25
+
26
+ # Activate observers that should always be running.
27
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
28
+
29
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
30
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
31
+ # config.time_zone = 'Central Time (US & Canada)'
32
+
33
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
34
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
35
+ # config.i18n.default_locale = :de
36
+
37
+ # Configure the default encoding used in templates for Ruby 1.9.
38
+ config.encoding = "utf-8"
39
+
40
+ # Configure sensitive parameters which will be filtered from the log file.
41
+ config.filter_parameters += [:password]
42
+
43
+ # Enable the asset pipeline
44
+ config.assets.enabled = true
45
+
46
+ # Version of your assets, change this if you want to expire all your assets
47
+ config.assets.version = '1.0'
48
+ end
49
+ end
50
+ end
data/config/boot.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ match "search" => "search#index", :as => :search
3
+
4
+ end
5
+
@@ -0,0 +1,8 @@
1
+ module Spud
2
+ module Search
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :base_layout
6
+ self.base_layout = "application"
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ require 'spud_core'
2
+ require 'spud_search/searchable'
3
+
4
+ require 'acts_as_indexed'
5
+ module Spud
6
+ module Search
7
+ class Engine < Rails::Engine
8
+ engine_name :spud_search
9
+ initializer :admin do
10
+ Spud::Core.configure do |config|
11
+ config.admin_applications += [{:name => "Search",:thumbnail => "spud/admin/template_thumb.png",:url => "/spud/admin/template_root",:order => 10}]
12
+ end
13
+ end
14
+ initializer :assets do |config|
15
+ Rails.application.config.assets.precompile += [
16
+ "spud/admin/search*"
17
+ ]
18
+ end
19
+
20
+ initializer :model_overrides do |config|
21
+ ActiveRecord::Base.class_eval do
22
+ include Spud::Search::Searchable
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ module Spud::Search::Searchable
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ extend ClassMethods
5
+ end
6
+ module ClassMethods
7
+ def searchable
8
+ if self.name == 'SpudPage'
9
+ self.instance_eval do
10
+ acts_as_indexed :fields => [:name,:meta_keywords,:meta_description], :if => Proc.new { |page| page.published == true && page.visibility == 0 }
11
+ end
12
+ end
13
+ if self.name == 'SpudPost'
14
+ self.instance_eval do
15
+ acts_as_indexed :fields => [:title,:content], :if => Proc.new { |post| post.published_at <= Time.now.utc && post.visible == true }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module Spud
2
+ module Search
3
+ require 'spud_search/configuration'
4
+ require 'spud_search/engine' if defined?(Rails)
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spud_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Estes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spud_core
16
+ requirement: &70230919566400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70230919566400
25
+ - !ruby/object:Gem::Dependency
26
+ name: acts_as_indexed
27
+ requirement: &70230919563780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.7
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70230919563780
36
+ description:
37
+ email: destes@redwindsw.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - app/assets/javascripts/search.js
43
+ - app/assets/javascripts/spud/admin/users.js
44
+ - app/assets/javascripts/spud/user_sessions.js
45
+ - app/assets/stylesheets/search.css
46
+ - app/controllers/search_controller.rb
47
+ - app/helpers/search_helper.rb
48
+ - app/helpers/spud/admin/users_helper.rb
49
+ - app/helpers/spud/user_sessions_helper.rb
50
+ - app/views/search/index.html.erb
51
+ - config/application.rb
52
+ - config/boot.rb
53
+ - config/routes.rb
54
+ - lib/spud_search.rb
55
+ - lib/spud_search/configuration.rb
56
+ - lib/spud_search/engine.rb
57
+ - lib/spud_search/searchable.rb
58
+ homepage:
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.15
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Spud Search Engine
82
+ test_files: []