simple-search 0.12.0 → 0.13.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.
- data/README.rdoc +1 -1
- data/Rakefile +10 -17
- data/VERSION +1 -1
- data/lib/simple_search/view_helper.rb +8 -8
- data/simple-search.gemspec +2 -2
- data/spec/simple_search_view_helper_spec.rb +5 -1
- metadata +3 -3
    
        data/README.rdoc
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    | @@ -28,23 +28,6 @@ Jeweler::Tasks.new do |gem| | |
| 28 28 | 
             
            end
         | 
| 29 29 | 
             
            Jeweler::RubygemsDotOrgTasks.new
         | 
| 30 30 |  | 
| 31 | 
            -
            require 'rake/testtask'
         | 
| 32 | 
            -
            Rake::TestTask.new(:test) do |test|
         | 
| 33 | 
            -
              test.libs << 'lib' << 'test'
         | 
| 34 | 
            -
              test.pattern = 'test/**/test_*.rb'
         | 
| 35 | 
            -
              test.verbose = true
         | 
| 36 | 
            -
            end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
            require 'rcov/rcovtask'
         | 
| 39 | 
            -
            Rcov::RcovTask.new do |test|
         | 
| 40 | 
            -
              test.libs << 'test'
         | 
| 41 | 
            -
              test.pattern = 'test/**/test_*.rb'
         | 
| 42 | 
            -
              test.verbose = true
         | 
| 43 | 
            -
              test.rcov_opts << '--exclude "gems/*"'
         | 
| 44 | 
            -
            end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            task :default => :test
         | 
| 47 | 
            -
             | 
| 48 31 | 
             
            require 'rdoc/task'
         | 
| 49 32 | 
             
            Rake::RDocTask.new do |rdoc|
         | 
| 50 33 | 
             
              version = File.exist?('VERSION') ? File.read('VERSION') : ""
         | 
| @@ -54,3 +37,13 @@ Rake::RDocTask.new do |rdoc| | |
| 54 37 | 
             
              rdoc.rdoc_files.include('README*')
         | 
| 55 38 | 
             
              rdoc.rdoc_files.include('lib/**/*.rb')
         | 
| 56 39 | 
             
            end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            require 'rspec/core/rake_task'
         | 
| 42 | 
            +
            desc 'Default: run specs.'
         | 
| 43 | 
            +
            task :default => :spec
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            desc "Run specs"
         | 
| 46 | 
            +
            RSpec::Core::RakeTask.new do |t|
         | 
| 47 | 
            +
              t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
         | 
| 48 | 
            +
              # Put spec opts in a file named .rspec in root
         | 
| 49 | 
            +
            end
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.13.0
         | 
| @@ -48,7 +48,7 @@ module SimpleSearch | |
| 48 48 | 
             
            		# 
         | 
| 49 49 | 
             
            		# Returns page related properties in hash
         | 
| 50 50 | 
             
            		#
         | 
| 51 | 
            -
            		def page_properties(arel)
         | 
| 51 | 
            +
            		def page_properties(arel, page_options={})
         | 
| 52 52 | 
             
            			total_rows = arel.limit(1000000).offset(0).count
         | 
| 53 53 |  | 
| 54 54 | 
             
            			# check if page is in an url array
         | 
| @@ -72,7 +72,7 @@ module SimpleSearch | |
| 72 72 | 
             
            				:current_page => (page || 1).to_i,
         | 
| 73 73 | 
             
            				:rows_per_page => (page_by || 30).to_i,
         | 
| 74 74 | 
             
            				:page_arr_key => page_arr_key
         | 
| 75 | 
            -
            			}
         | 
| 75 | 
            +
            			}.merge(page_options)
         | 
| 76 76 | 
             
            		end
         | 
| 77 77 |  | 
| 78 78 | 
             
            		# 
         | 
| @@ -91,9 +91,9 @@ module SimpleSearch | |
| 91 91 | 
             
            		# 
         | 
| 92 92 | 
             
            		# Returns page url params in hash with the page number as key
         | 
| 93 93 | 
             
            		#
         | 
| 94 | 
            -
            		def page_url_params(arel,  | 
| 95 | 
            -
            			page_props  | 
| 96 | 
            -
                  num_pages  =  | 
| 94 | 
            +
            		def page_url_params(arel, page_props=nil)
         | 
| 95 | 
            +
            			page_props ||= page_properties(arel)
         | 
| 96 | 
            +
                  num_pages  = page_props[:num_pages] || 5 
         | 
| 97 97 | 
             
            			num_bf_af = (num_pages-1)/2
         | 
| 98 98 | 
             
            			current_page = page_props[:current_page]
         | 
| 99 99 | 
             
            			last_page    = page_props[:last_page]
         | 
| @@ -111,11 +111,11 @@ module SimpleSearch | |
| 111 111 | 
             
            			page_url_params
         | 
| 112 112 | 
             
            		end
         | 
| 113 113 |  | 
| 114 | 
            -
            		def page_urls(arel, http_options={})
         | 
| 114 | 
            +
            		def page_urls(arel, page_options={}, http_options={})
         | 
| 115 115 | 
             
            			page_urls = []
         | 
| 116 116 | 
             
            			prev_page = 0	
         | 
| 117 | 
            -
                  page_props = page_properties(arel)
         | 
| 118 | 
            -
            			page_url_params(arel,  | 
| 117 | 
            +
                  page_props = page_properties(arel, page_options)
         | 
| 118 | 
            +
            			page_url_params(arel, page_props ).each { |page, url_params|
         | 
| 119 119 | 
             
            				if page.to_i > (prev_page+1) # page number jumped up, need to have some indicator
         | 
| 120 120 | 
             
            					page_urls << "<span class='filler'>...</span>"
         | 
| 121 121 | 
             
            				end
         | 
    
        data/simple-search.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = "simple-search"
         | 
| 8 | 
            -
              s.version = "0. | 
| 8 | 
            +
              s.version = "0.13.0"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Allen Kim"]
         | 
| 12 | 
            -
              s.date = "2012-03- | 
| 12 | 
            +
              s.date = "2012-03-27"
         | 
| 13 13 | 
             
              s.description = "\n\t\tTranslates url commands for searching, paging, sorting, groupion against ActiveRecord and its associations.\n\t\tProvides view helpers including links for order and urls for search, group, and page.\n\t"
         | 
| 14 14 | 
             
              s.email = "bighostkim@gmail.com"
         | 
| 15 15 | 
             
              s.extra_rdoc_files = [
         | 
| @@ -88,7 +88,7 @@ describe SimpleSearch::ViewHelper do | |
| 88 88 | 
             
              end
         | 
| 89 89 |  | 
| 90 90 | 
             
              describe "#page_urls" do
         | 
| 91 | 
            -
                it "generate page urls" do
         | 
| 91 | 
            +
                it "generate page urls by given numbers(default 5)" do
         | 
| 92 92 | 
             
                  arel = Post.select('posts.*, post_likes.*').joins(:post_likes).simplesearch(:page_by=>30)
         | 
| 93 93 | 
             
                  @view.request = ActionController::TestRequest.new({"SCRIPT_NAME"=>"/tests",
         | 
| 94 94 | 
             
                      "QUERY_STRING"=>"controller=tests&page=5&page_by=10"})
         | 
| @@ -96,7 +96,11 @@ describe SimpleSearch::ViewHelper do | |
| 96 96 | 
             
                  page_urls.length.should == 9 # 1 ... 3 4 5 6 7 ... 10
         | 
| 97 97 | 
             
                  page_urls[1].should eq "<span class='filler'>...</span>"
         | 
| 98 98 | 
             
                  page_urls[7].should eq "<span class='filler'>...</span>"
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                  page_urls = @view.page_urls(arel,:num_pages=>7)
         | 
| 101 | 
            +
                  page_urls.length.should == 10 # 1 2 3 4 5 6 7 8 ... 10
         | 
| 99 102 | 
             
                end
         | 
| 103 | 
            +
             | 
| 100 104 | 
             
              end
         | 
| 101 105 |  | 
| 102 106 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 | 
             
            name: simple-search
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 4 | 
             
              prerelease: 
         | 
| 5 | 
            -
              version: 0. | 
| 5 | 
            +
              version: 0.13.0
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors: 
         | 
| 8 8 | 
             
            - Allen Kim
         | 
| @@ -10,7 +10,7 @@ autorequire: | |
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 12 |  | 
| 13 | 
            -
            date: 2012-03- | 
| 13 | 
            +
            date: 2012-03-27 00:00:00 Z
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 16 16 | 
             
              name: activerecord
         | 
| @@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 163 163 | 
             
              requirements: 
         | 
| 164 164 | 
             
              - - ">="
         | 
| 165 165 | 
             
                - !ruby/object:Gem::Version 
         | 
| 166 | 
            -
                  hash:  | 
| 166 | 
            +
                  hash: -265750120203918884
         | 
| 167 167 | 
             
                  segments: 
         | 
| 168 168 | 
             
                  - 0
         | 
| 169 169 | 
             
                  version: "0"
         |