merb-search 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Jamie Hoover
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,51 @@
1
+ Installation:
2
+
3
+ 1.) Install merb-search gem.
4
+ sudo gem install merb-search
5
+
6
+ 2.) Navigate to your merb application.
7
+ cd ~/your_merb_app/
8
+
9
+ 3.) Add to your dependencies file.
10
+ vim config/dependencies.rb
11
+ a
12
+
13
+ dependency 'merb-search'
14
+
15
+ esc : wq
16
+
17
+ 4.) Add options to your init file in the before_app_loads callback.
18
+ vim config/init.rb
19
+ a
20
+
21
+ Merb::BootLoader.before_app_loads do
22
+ boss.appid = 'Bossdemo'
23
+ end
24
+
25
+ esc : wq
26
+
27
+ 5.) Add to your router file.
28
+ vim config/router.rb
29
+ a
30
+
31
+ slice(:merb_search)
32
+
33
+ esc : wq
34
+
35
+ 6.) Start your merb application and search.
36
+ http://your_domain/search
37
+
38
+ ------------------------------------------------------------------------------
39
+
40
+ Advanced:
41
+
42
+ # List all available tasks:
43
+ rake -T slices:merb_photos
44
+
45
+ # Put your application-level overrides in:
46
+ host-app/slices/merb-search/
47
+
48
+ # Templates are located in this order:
49
+ 1. host-app/slices/merb-search/app/views/*
50
+ 2. gems/merb-search/app/views/*
51
+ 3. host-app/app/views/*
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'merb-core'
4
+ require 'merb-core/tasks/merb'
5
+
6
+ spec = Gem::Specification.new do |s|
7
+ s.add_dependency('merb-slices', '~> 1.0.0')
8
+ s.add_dependency('merb-ui', '>= 0.3')
9
+ s.author = 'UiPoet'
10
+ s.email = 'dont.tase@me.com'
11
+ s.files = FileList['app/**/*', 'lib/**/*', '[A-Z]*'].to_a
12
+ s.has_rdoc = true
13
+ s.homepage = 'http://uipoet.com'
14
+ s.name = 'merb-search'
15
+ s.rubyforge_project = 'uipoet'
16
+ s.summary = 'Search for Merb'
17
+ s.version = '0.1.1'
18
+ end
19
+
20
+ Rake::GemPackageTask.new(spec) do |pkg|
21
+ pkg.gem_spec = spec
22
+ end
23
+
24
+ desc 'Create gemspec'
25
+ task :gemspec do
26
+ File.open("#{spec.name}.gemspec", 'w') do |file|
27
+ file.puts spec.to_ruby
28
+ end
29
+ end
30
+
31
+ desc 'Install gem'
32
+ task :install do
33
+ Merb::RakeHelper.install(spec.name, :version => spec.version)
34
+ end
35
+
36
+ desc 'Release gem to rubyforge.org'
37
+ task :release do
38
+ require 'rubyforge'
39
+ sh 'sudo rake package'
40
+ begin
41
+ sh 'rubyforge login'
42
+ sh "rubyforge add_release #{spec.rubyforge_project} #{spec.name} #{spec.version} pkg/#{spec.name}-#{spec.version}.gem"
43
+ rescue Exception => e
44
+ puts "Release failed: #{e.message}"
45
+ end
46
+ end
47
+
48
+ desc 'Uninstall gem'
49
+ task :uninstall do
50
+ Merb::RakeHelper.uninstall(spec.name, :version => spec.name)
51
+ end
@@ -0,0 +1,5 @@
1
+ class MerbSearch::Application < Merb::Controller
2
+
3
+ controller_for_slice
4
+
5
+ end
@@ -0,0 +1,45 @@
1
+ class MerbSearch::Search < MerbSearch::Application
2
+
3
+ def index
4
+
5
+ render
6
+
7
+ end
8
+
9
+ def images
10
+
11
+ @query = params[:q] || 'merb'
12
+ @images = boss.images.new(@query, :count => 12).resultset
13
+ @news = boss.news.new(@query, :age => '1d', :count => 3).resultset
14
+ @spelling = boss.web.new(@query).resultset
15
+ @web = boss.web.new(@query, :count => 3).resultset
16
+
17
+ display @images
18
+
19
+ end
20
+
21
+ def news
22
+
23
+ @query = params[:q] || 'merb'
24
+ @images = boss.images.new(@query, :count => 3).resultset
25
+ @news = boss.news.new(@query, :age => '1w', :count => 12).resultset
26
+ @spelling = boss.web.new(@query).resultset
27
+ @web = boss.web.new(@query, :count => 3).resultset
28
+
29
+ display @news
30
+
31
+ end
32
+
33
+ def web
34
+
35
+ @query = params[:q] || 'merb'
36
+ @images = boss.images.new(@query, :count => 3).resultset
37
+ @news = boss.news.new(@query, :age => '1d', :count => 3).resultset
38
+ @spelling = boss.web.new(@query).resultset
39
+ @web = boss.web.new(@query, :count => 12).resultset
40
+
41
+ display @web
42
+
43
+ end
44
+
45
+ end
File without changes
@@ -0,0 +1,37 @@
1
+ <%= mui_grid(:cell_valign => 'top', :columns => 2, :width => '100%') do %>
2
+ <%= mui_cell do %>
3
+ <% @web.each do |result| %>
4
+ <%= mui_tray(:inline => true, :title => result.title, :title_url => result.clickurl, :width => '20em') do %>
5
+ <%= mui_block(:height => '8em') do %>
6
+ <%= result.abstract %>
7
+ <% end =%>
8
+ <%= mui_block(:subtle => true) do %>
9
+ <%= result.date %>
10
+ <% end =%>
11
+ <%= mui_block(:subtle => true, :truncate => true) do %>
12
+ <%= result.dispurl(:wbr => false) %>
13
+ <% end =%>
14
+ <% end =%>
15
+ <% end %>
16
+ <% end =%>
17
+ <%= mui_cell do %>
18
+ <%= mui_tray(:title => 'Images', :inline => true, :width => '20em') do %>
19
+ <%= mui_grid(:columns => 3, :width => '100%') do %>
20
+ <% @images.each do |result| %>
21
+ <%= mui_cell do %>
22
+ <%= mui_link(:url => result.clickurl) do %>
23
+ <%= mui_image(:height => 60, :url => result.thumbnail_url, :width => 60) %>
24
+ <% end =%>
25
+ <% end =%>
26
+ <% end %>
27
+ <% end =%>
28
+ <% end =%>
29
+ <%= mui_tray(:title => 'News', :inline => true, :width => '20em') do %>
30
+ <% @news.each do |result| %>
31
+ <%= mui_block(:width => '200px') do %>
32
+ <%= mui_link(:title => result.title, :url => result.clickurl) %> <span class="mui_date"><%= result.time %></span>
33
+ <% end =%>
34
+ <% end %>
35
+ <% end =%>
36
+ <% end =%>
37
+ <% end =%>
@@ -0,0 +1,103 @@
1
+ namespace :slices do
2
+ namespace :merb_search do
3
+
4
+ desc "Install MerbSearch"
5
+ task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
6
+
7
+ desc "Test for any dependencies"
8
+ task :preflight do # see slicetasks.rb
9
+ end
10
+
11
+ desc "Setup directories"
12
+ task :setup_directories do
13
+ puts "Creating directories for host application"
14
+ MerbSearch.mirrored_components.each do |type|
15
+ if File.directory?(MerbSearch.dir_for(type))
16
+ if !File.directory?(dst_path = MerbSearch.app_dir_for(type))
17
+ relative_path = dst_path.relative_path_from(Merb.root)
18
+ puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
19
+ mkdir_p(dst_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Copy stub files to host application"
26
+ task :stubs do
27
+ puts "Copying stubs for MerbSearch - resolves any collisions"
28
+ copied, preserved = MerbSearch.mirror_stubs!
29
+ puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ copied.each { |f| puts "- copied #{f}" }
31
+ preserved.each { |f| puts "! preserved override as #{f}" }
32
+ end
33
+
34
+ desc "Copy stub files and views to host application"
35
+ task :patch => [ "stubs", "freeze:views" ]
36
+
37
+ desc "Copy public assets to host application"
38
+ task :copy_assets do
39
+ puts "Copying assets for MerbSearch - resolves any collisions"
40
+ copied, preserved = MerbSearch.mirror_public!
41
+ puts "- no files to copy" if copied.empty? && preserved.empty?
42
+ copied.each { |f| puts "- copied #{f}" }
43
+ preserved.each { |f| puts "! preserved override as #{f}" }
44
+ end
45
+
46
+ desc "Migrate the database"
47
+ task :migrate do # see slicetasks.rb
48
+ end
49
+
50
+ desc "Freeze MerbSearch into your app (only merb-search/app)"
51
+ task :freeze => [ "freeze:app" ]
52
+
53
+ namespace :freeze do
54
+
55
+ desc "Freezes MerbSearch by installing the gem into application/gems"
56
+ task :gem do
57
+ ENV["GEM"] ||= "merb-search"
58
+ Rake::Task['slices:install_as_gem'].invoke
59
+ end
60
+
61
+ desc "Freezes MerbSearch by copying all files from merb-search/app to your application"
62
+ task :app do
63
+ puts "Copying all merb-search/app files to your application - resolves any collisions"
64
+ copied, preserved = MerbSearch.mirror_app!
65
+ puts "- no files to copy" if copied.empty? && preserved.empty?
66
+ copied.each { |f| puts "- copied #{f}" }
67
+ preserved.each { |f| puts "! preserved override as #{f}" }
68
+ end
69
+
70
+ desc "Freeze all views into your application for easy modification"
71
+ task :views do
72
+ puts "Copying all view templates to your application - resolves any collisions"
73
+ copied, preserved = MerbSearch.mirror_files_for :view
74
+ puts "- no files to copy" if copied.empty? && preserved.empty?
75
+ copied.each { |f| puts "- copied #{f}" }
76
+ preserved.each { |f| puts "! preserved override as #{f}" }
77
+ end
78
+
79
+ desc "Freeze all models into your application for easy modification"
80
+ task :models do
81
+ puts "Copying all models to your application - resolves any collisions"
82
+ copied, preserved = MerbSearch.mirror_files_for :model
83
+ puts "- no files to copy" if copied.empty? && preserved.empty?
84
+ copied.each { |f| puts "- copied #{f}" }
85
+ preserved.each { |f| puts "! preserved override as #{f}" }
86
+ end
87
+
88
+ desc "Freezes MerbSearch as a gem and copies over merb-search/app"
89
+ task :app_with_gem => [:gem, :app]
90
+
91
+ desc "Freezes MerbSearch by unpacking all files into your application"
92
+ task :unpack do
93
+ puts "Unpacking MerbSearch files to your application - resolves any collisions"
94
+ copied, preserved = MerbSearch.unpack_slice!
95
+ puts "- no files to copy" if copied.empty? && preserved.empty?
96
+ copied.each { |f| puts "- copied #{f}" }
97
+ preserved.each { |f| puts "! preserved override as #{f}" }
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,18 @@
1
+ namespace :slices do
2
+ namespace :merb_search do
3
+
4
+ # add your own merb-search tasks here
5
+
6
+ # implement this to test for structural/code dependencies
7
+ # like certain directories or availability of other files
8
+ desc "Test for any dependencies"
9
+ task :preflight do
10
+ end
11
+
12
+ # implement this to perform any database related setup steps
13
+ desc "Migrate the database"
14
+ task :migrate do
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,65 @@
1
+ namespace :slices do
2
+ namespace :merb_search do
3
+
4
+ desc "Run slice specs within the host application context"
5
+ task :spec => [ "spec:explain", "spec:default" ]
6
+
7
+ namespace :spec do
8
+
9
+ slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
+
11
+ task :explain do
12
+ puts "\nNote: By running MerbSearch specs inside the application context any\n" +
13
+ "overrides could break existing specs. This isn't always a problem,\n" +
14
+ "especially in the case of views. Use these spec tasks to check how\n" +
15
+ "well your application conforms to the original slice implementation."
16
+ end
17
+
18
+ Spec::Rake::SpecTask.new('default') do |t|
19
+ t.spec_opts = ["--format", "specdoc", "--colour"]
20
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
21
+ end
22
+
23
+ desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
24
+ Spec::Rake::SpecTask.new('model') do |t|
25
+ t.spec_opts = ["--format", "specdoc", "--colour"]
26
+ if(ENV['MODEL'])
27
+ t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
28
+ else
29
+ t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
30
+ end
31
+ end
32
+
33
+ desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
34
+ Spec::Rake::SpecTask.new('controller') do |t|
35
+ t.spec_opts = ["--format", "specdoc", "--colour"]
36
+ if(ENV['CONTROLLER'])
37
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
38
+ else
39
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
40
+ end
41
+ end
42
+
43
+ desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
44
+ Spec::Rake::SpecTask.new('view') do |t|
45
+ t.spec_opts = ["--format", "specdoc", "--colour"]
46
+ if(ENV['CONTROLLER'] and ENV['VIEW'])
47
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
48
+ elsif(ENV['CONTROLLER'])
49
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
50
+ else
51
+ t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
52
+ end
53
+ end
54
+
55
+ desc "Run all specs and output the result in html"
56
+ Spec::Rake::SpecTask.new('html') do |t|
57
+ t.spec_opts = ["--format", "html"]
58
+ t.libs = ['lib', 'server/lib' ]
59
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,28 @@
1
+ if defined?(Merb::Plugins)
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ dependencies('boss', 'merb-ui')
6
+
7
+ Merb::Plugins.add_rakefiles('merb-search/merbtasks', 'merb-search/slicetasks', 'merb-search/spectasks')
8
+
9
+ Merb::Slices::register(__FILE__)
10
+
11
+ Merb::Slices::config[:merb_search][:layout] ||= :application
12
+
13
+ module MerbSearch
14
+
15
+ def self.setup_router(scope)
16
+ scope.to(:controller => 'search') do |s|
17
+ s.match('/').to(:action => 'index').name(:index)
18
+ s.match('/images').to(:action => 'images').name(:images)
19
+ s.match('/news').to(:action => 'news').name(:news)
20
+ s.match('/web').to(:action => 'web').name(:web)
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ MerbSearch.setup_default_structure!
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb-search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - UiPoet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-16 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-slices
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: merb-ui
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0.3"
34
+ version:
35
+ description:
36
+ email: dont.tase@me.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - app/controllers
45
+ - app/controllers/application.rb
46
+ - app/controllers/search.rb
47
+ - app/views
48
+ - app/views/search
49
+ - app/views/search/index.html.erb
50
+ - app/views/search/web.html.erb
51
+ - lib/merb-search
52
+ - lib/merb-search/merbtasks.rb
53
+ - lib/merb-search/slicetasks.rb
54
+ - lib/merb-search/spectasks.rb
55
+ - lib/merb-search.rb
56
+ - LICENSE
57
+ - Rakefile
58
+ - README
59
+ has_rdoc: true
60
+ homepage: http://uipoet.com
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project: uipoet
81
+ rubygems_version: 1.3.1
82
+ signing_key:
83
+ specification_version: 2
84
+ summary: Search for Merb
85
+ test_files: []
86
+