peiji-san 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../test_helper', __FILE__)
2
2
 
3
- describe "PeijiSan mixin" do
3
+ describe "A model extended by PeijiSan" do
4
4
  it "should define an #entries_per_page= class method with which the max amount of entries per page is specified" do
5
5
  Member.should.respond_to :entries_per_page=
6
6
  Member.instance_variable_get(:@entries_per_page).should.be 10
@@ -15,7 +15,7 @@ describe "PeijiSan mixin" do
15
15
  end
16
16
  end
17
17
 
18
- describe "PeijiSan::PageScope" do
18
+ describe "The PeijiSan extended scope" do
19
19
  before do
20
20
  PeijiSanTest::Initializer.setup_database
21
21
  199.times { |i| Member.create(:name => "KRS #{i}") }
@@ -25,68 +25,67 @@ describe "PeijiSan::PageScope" do
25
25
  PeijiSanTest::Initializer.teardown_database
26
26
  end
27
27
 
28
- it "should have defined a named_scope called :page which returns the entries belonging to the page number given" do
28
+ it "returns entries for the specified page" do
29
29
  page_1 = Member.page(1)
30
- page_1.class.should.be PeijiSan::PageScope
31
30
  page_1.length.should.be 10
32
31
  page_1.should == Member.find(:all, :offset => 0, :limit => 10)
33
32
  end
34
33
 
35
- it "should return the correct count of pages for the current scope" do
34
+ it "returns the correct count of pages" do
36
35
  Member.all_like_krs_1.page(1).page_count.should.be 11
37
36
  end
38
37
 
39
- it "should know the current page number" do
38
+ it "knows the current page number" do
40
39
  Member.page(2).current_page.should.be 2
41
40
  Member.page(4).current_page.should.be 4
42
41
  end
43
42
 
44
- it "should know if there's a next page" do
45
- Member.page(1).should.have_next_page
46
- Member.page(20).should.not.have_next_page
47
- Member.all_like_krs_1.but_ending_with_9.page(1).should.not.have_next_page
43
+ it "knows if there's a next page" do
44
+ Member.page(1).should.next_page
45
+ Member.page(20).should.not.next_page
46
+ Member.all_like_krs_1.but_ending_with_9.page(1).should.not.next_page
48
47
  end
49
48
 
50
- it "should return the next page" do
49
+ it "returns the next page number" do
51
50
  Member.page(1).next_page.should.be 2
52
51
  Member.page(20).next_page.should.be nil
53
52
  end
54
53
 
55
- it "should know if there's a previous page" do
56
- Member.page(1).should.not.have_previous_page
57
- Member.page(20).should.have_previous_page
54
+ it "knows if there's a previous page" do
55
+ Member.page(1).should.not.previous_page
56
+ Member.page(20).should.previous_page
58
57
  end
59
58
 
60
- it "should return the previous page" do
59
+ it "returns the previous page" do
61
60
  Member.page(1).previous_page.should.be nil
62
61
  Member.page(20).previous_page.should.be 19
63
62
  end
64
63
 
65
- it "should return if a given page number is the current page" do
64
+ it "knows if a given page number is the current page" do
66
65
  assert Member.page(1).current_page?(1)
67
66
  assert !Member.page(1).current_page?(2)
68
67
  end
69
68
 
70
- it "should default to page 1 if no valid page argument was given" do
69
+ it "defaults to page 1 if no valid page argument was given" do
71
70
  Member.page(nil).current_page.should.be 1
72
71
  Member.page('').current_page.should.be 1
73
72
  end
74
73
 
75
- it "should cast the page argument to an integer" do
74
+ it "casts the page argument to an integer" do
76
75
  Member.page('2').current_page.should.be 2
77
76
  end
78
77
 
79
- it "should take an optional second argument which overrides the entries_per_page setting" do
78
+ it "takes an optional second argument which overrides the entries_per_page setting" do
80
79
  Member.all_like_krs_1.page(1, 20).page_count.should.be 6
81
80
  end
82
81
 
83
- it "should return the count of all the entries across all pages for the current scope" do
84
- Member.all_like_krs_1.page(1).count.should.be 110
85
- Member.all_like_krs_1.page(2).count.should.be 110
86
- Member.all_like_krs_1.but_ending_with_9.page(1).count.should.be 10
82
+ it "returns the count of all the entries across all pages for the current scope" do
83
+ Member.all_like_krs_1.page(1).unpaged_count.should.be 110
84
+ Member.all_like_krs_1.page(2).unpaged_count.should.be 110
85
+ Member.all_like_krs_1.but_ending_with_9.page(1).unpaged_count.should.be 10
87
86
  end
88
87
 
89
- it "should still work when chained with other regular named scopes" do
88
+ it "works when chained with other regular named scopes" do
90
89
  Member.all_like_krs_1.page(1).page_count.should.be 11
91
90
  Member.all_like_krs_1.but_ending_with_9.page(2).page_count.should.be 1
92
91
 
data/test/test_helper.rb CHANGED
@@ -1,40 +1,22 @@
1
1
  module PeijiSanTest
2
2
  module Initializer
3
- VENDOR_RAILS = File.expand_path('../../../../rails', __FILE__)
4
- OTHER_RAILS = File.expand_path('../../../rails', __FILE__)
5
- PLUGIN_ROOT = File.expand_path('../../', __FILE__)
6
-
7
- def self.rails_directory
8
- if File.exist?(File.join(VENDOR_RAILS, 'railties'))
9
- VENDOR_RAILS
10
- elsif File.exist?(File.join(OTHER_RAILS, 'railties'))
11
- OTHER_RAILS
12
- end
13
- end
14
-
15
3
  def self.load_dependencies
16
- if rails_directory
17
- $:.unshift(File.join(rails_directory, 'activesupport', 'lib'))
18
- $:.unshift(File.join(rails_directory, 'activerecord', 'lib'))
19
- $:.unshift(File.join(rails_directory, 'actionpack', 'lib'))
20
- else
21
- require 'rubygems' rescue LoadError
22
- end
4
+ $:.unshift File.expand_path('../../lib', __FILE__)
5
+
6
+ require 'rubygems' rescue LoadError
23
7
 
24
8
  require 'active_support'
25
9
  require 'active_record'
26
10
  require 'action_view'
27
11
 
28
- require 'rubygems' rescue LoadError
29
-
30
12
  require 'test/spec'
31
13
  require 'mocha'
32
14
 
33
- require File.join(PLUGIN_ROOT, 'rails', 'init')
15
+ require File.expand_path('../../init', __FILE__)
34
16
  end
35
17
 
36
18
  def self.configure_database
37
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
19
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
38
20
  ActiveRecord::Migration.verbose = false
39
21
  end
40
22
 
@@ -68,21 +50,12 @@ end
68
50
 
69
51
  PeijiSanTest::Initializer.start
70
52
 
71
- class PeijiSan::PageScope
72
- instance_methods.each { |method| alias_method method.sub(/^has_/, 'have_'), method if method =~ /^has_/ }
73
-
74
- # The delegation of all methods in NamedScope breaks #should.
75
- def should
76
- Test::Spec::Should.new(self)
77
- end
78
- end
79
-
80
53
  class Member < ActiveRecord::Base
81
54
  extend PeijiSan
82
55
  self.entries_per_page = 10
83
56
 
84
- named_scope :all_like_krs_1, :conditions => "name LIKE 'KRS 1%'"
85
- named_scope :but_ending_with_9, :conditions => "name LIKE '%9'"
57
+ scope :all_like_krs_1, where("name LIKE 'KRS 1%'")
58
+ scope :but_ending_with_9, where("name LIKE '%9'")
86
59
 
87
60
  has_many :works
88
61
  end
@@ -91,5 +64,5 @@ class Work < ActiveRecord::Base
91
64
  extend PeijiSan
92
65
  self.entries_per_page = 5
93
66
 
94
- named_scope :uploaded, :conditions => { :status => 'uploaded' }
67
+ scope :uploaded, where(:status => 'uploaded')
95
68
  end
@@ -4,15 +4,6 @@ class TestController
4
4
  def params
5
5
  @params ||= {}
6
6
  end
7
-
8
- def url_for(options)
9
- url = "/collections"
10
- url += "?page=#{options[:page]}" if options[:page]
11
- url += "?pagina=#{options[:pagina]}" if options[:pagina]
12
- url += "&starts_with=#{options[:starts_with]}" if options[:starts_with]
13
- url += "##{options[:anchor]}" if options[:anchor]
14
- url
15
- end
16
7
  end
17
8
 
18
9
  module PeijiSanHelperTestHelper
@@ -31,6 +22,19 @@ module PeijiSanHelperTestHelper
31
22
  collection.stubs(:current_page?).with(2).returns(false)
32
23
  collection.stubs(:page_count).returns(125)
33
24
  end
25
+
26
+ def url_for(options)
27
+ return options if options.kind_of?(String)
28
+
29
+ options = options.with_indifferent_access
30
+
31
+ url = "/collections"
32
+ url += "?page=#{options[:page]}" if options[:page]
33
+ url += "?pagina=#{options[:pagina]}" if options[:pagina]
34
+ url += "&starts_with=#{options[:starts_with]}" if options[:starts_with]
35
+ url += "##{options[:anchor]}" if options[:anchor]
36
+ url
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -40,11 +44,11 @@ describe "PeijiSan::ViewHelper::link_to_page" do
40
44
  include PeijiSan::ViewHelper
41
45
 
42
46
  it "should return a link for a given page number" do
43
- link_to_page(2, collection).should == '<a href="/collections?page=2#explore">2</a>'
47
+ link_to_page(2, collection).should == '<a href="/collections?page=2">2</a>'
44
48
  end
45
49
 
46
50
  it "should return a link for a given page number with the specified page parameter" do
47
- link_to_page(2, collection, :page_parameter => 'pagina').should == '<a href="/collections?pagina=2#explore">2</a>'
51
+ link_to_page(2, collection, :page_parameter => 'pagina').should == '<a href="/collections?pagina=2">2</a>'
48
52
  end
49
53
 
50
54
  it "should return a link for a given page number with the specified anchor" do
@@ -53,7 +57,7 @@ describe "PeijiSan::ViewHelper::link_to_page" do
53
57
 
54
58
  it "should return a link for a given page number and include the original params" do
55
59
  controller.params[:starts_with] = 'h'
56
- link_to_page(2, collection).should == '<a href="/collections?page=2&amp;starts_with=h#explore">2</a>'
60
+ link_to_page(2, collection).should == '<a href="/collections?page=2&amp;starts_with=h">2</a>'
57
61
  end
58
62
 
59
63
  it "should return a link which does not include the page GET variable if it's page number 1" do
@@ -63,12 +67,12 @@ describe "PeijiSan::ViewHelper::link_to_page" do
63
67
 
64
68
  it "should return a link with the class current if it's for the currently selected page" do
65
69
  collection.stubs(:current_page?).with(2).returns(true)
66
- link_to_page(2, collection).should == '<a href="/collections?page=2#explore" class="current">2</a>'
70
+ link_to_page(2, collection).should == '<a href="/collections?page=2" class="current">2</a>'
67
71
  end
68
72
 
69
73
  it "should return a link with the class current if it's for the currently selected page" do
70
74
  collection.stubs(:current_page?).with(2).returns(true)
71
- link_to_page(2, collection, :current_class => 'looking_at').should == '<a href="/collections?page=2#explore" class="looking_at">2</a>'
75
+ link_to_page(2, collection, :current_class => 'looking_at').should == '<a href="/collections?page=2" class="looking_at">2</a>'
72
76
  end
73
77
  end
74
78
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peiji-san
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Eloy Duran
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-22 00:00:00 +01:00
18
+ date: 2011-04-05 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -22,16 +28,30 @@ extensions: []
22
28
  extra_rdoc_files:
23
29
  - LICENSE
24
30
  - README.rdoc
31
+ - TODO
25
32
  files:
26
33
  - LICENSE
27
34
  - README.rdoc
28
35
  - Rakefile
29
36
  - TODO
30
37
  - VERSION.yml
38
+ - init.rb
31
39
  - lib/peiji_san.rb
32
40
  - lib/peiji_san/view_helper.rb
33
41
  - peiji-san.gemspec
34
- - rails/init.rb
42
+ - rdoc/classes/PeijiSan.html
43
+ - rdoc/classes/PeijiSan/PaginationMethods.html
44
+ - rdoc/classes/PeijiSan/ViewHelper.html
45
+ - rdoc/created.rid
46
+ - rdoc/files/LICENSE.html
47
+ - rdoc/files/README_rdoc.html
48
+ - rdoc/files/lib/peiji_san/view_helper_rb.html
49
+ - rdoc/files/lib/peiji_san_rb.html
50
+ - rdoc/fr_class_index.html
51
+ - rdoc/fr_file_index.html
52
+ - rdoc/fr_method_index.html
53
+ - rdoc/index.html
54
+ - rdoc/rdoc-style.css
35
55
  - test/peiji_san_test.rb
36
56
  - test/test_helper.rb
37
57
  - test/view_helper_test.rb
@@ -40,26 +60,32 @@ homepage: http://github.com/Fingertips/peiji-san
40
60
  licenses: []
41
61
 
42
62
  post_install_message:
43
- rdoc_options:
44
- - --charset=UTF-8
63
+ rdoc_options: []
64
+
45
65
  require_paths:
46
66
  - lib
47
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
48
69
  requirements:
49
70
  - - ">="
50
71
  - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
51
75
  version: "0"
52
- version:
53
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
54
78
  requirements:
55
79
  - - ">="
56
80
  - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
57
84
  version: "0"
58
- version:
59
85
  requirements: []
60
86
 
61
87
  rubyforge_project:
62
- rubygems_version: 1.3.5
88
+ rubygems_version: 1.5.2
63
89
  signing_key:
64
90
  specification_version: 3
65
91
  summary: PeijiSan is a Rails plugin which uses named scopes to create a thin pagination layer.