maiha-active_record_view 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README +25 -0
  2. data/Rakefile +22 -0
  3. data/arv/properties/boolean +4 -0
  4. data/arv/properties/date +5 -0
  5. data/arv/properties/datetime +5 -0
  6. data/arv/properties/default +3 -0
  7. data/arv/properties/integer +6 -0
  8. data/arv/properties/string +4 -0
  9. data/arv/properties/text +7 -0
  10. data/arv/properties/time +5 -0
  11. data/arv/properties/timestamp +5 -0
  12. data/arv/property.erb +19 -0
  13. data/init.rb +0 -0
  14. data/install.rb +1 -0
  15. data/lib/active_record_view.rb +2 -0
  16. data/lib/active_record_view/controller.rb +9 -0
  17. data/lib/active_record_view/default_actions.rb +29 -0
  18. data/lib/active_record_view/engines.rb +68 -0
  19. data/lib/active_record_view/helper.rb +152 -0
  20. data/lib/active_record_view/record_identifier.rb +42 -0
  21. data/lib/active_record_view/render_arv.rb +51 -0
  22. data/lib/active_record_view/write_exception.rb +11 -0
  23. data/lib/localized/model.rb +103 -0
  24. data/lib/localized/view_property.rb +337 -0
  25. data/spec/fixtures/card.rb +12 -0
  26. data/spec/fixtures/card/equip.rb +13 -0
  27. data/spec/fixtures/card/magic.rb +13 -0
  28. data/spec/fixtures/card/member.rb +13 -0
  29. data/spec/fixtures/card/unit.rb +13 -0
  30. data/spec/fixtures/deck.rb +2 -0
  31. data/spec/localized/decks.yml +39 -0
  32. data/spec/migrate/001_create_cards.rb +16 -0
  33. data/spec/migrate/002_create_decks.rb +5 -0
  34. data/spec/models/active_record_view_helper_spec.rb +393 -0
  35. data/spec/models/render_spec.rb +220 -0
  36. data/spec/schema.rb +30 -0
  37. data/spec/spec.opts +6 -0
  38. data/spec/spec_helper.rb +27 -0
  39. data/tasks/active_record_view_tasks.rake +37 -0
  40. data/test/active_record_view_test.rb +8 -0
  41. data/uninstall.rb +1 -0
  42. metadata +93 -0
@@ -0,0 +1,220 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ Arv = Struct.new(:name, :buffer, :options)
4
+ class Arv
5
+ include ActionView::Helpers::TagHelper
6
+ include ActiveRecordView::RenderArv
7
+
8
+ def execute
9
+ arv_erb_code(buffer, name, options || {}).gsub(/\n/, '')
10
+ end
11
+ end
12
+
13
+ describe ActiveRecordView::RenderArv, "IDと名前のARV" do
14
+ before(:each) do
15
+ @arv = Arv.new(:records, <<-ARV)
16
+ id = ID
17
+ name = 名前
18
+ ARV
19
+ end
20
+
21
+ it "IDと名前がTHに入る" do
22
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
23
+ <table class="arv-list records">
24
+ <thead>
25
+ <tr>
26
+ <th class='id' colspan=1>ID</th>
27
+ <th class='name' colspan=1>名前</th>
28
+ </tr>
29
+ </thead>
30
+ <%= collection_tbody_for(@records, %w( id name )) %>
31
+ </table>
32
+ ERB
33
+ end
34
+
35
+ it ":classで指定したクラス名がtableに追加される" do
36
+ @arv.options = { :class=>"simple" }
37
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
38
+ <table class="arv-list records simple">
39
+ <thead>
40
+ <tr>
41
+ <th class='id' colspan=1>ID</th>
42
+ <th class='name' colspan=1>名前</th>
43
+ </tr>
44
+ </thead>
45
+ <%= collection_tbody_for(@records, %w( id name )) %>
46
+ </table>
47
+ ERB
48
+ end
49
+ end
50
+
51
+
52
+ describe ActiveRecordView::RenderArv, "=を含まない場合" do
53
+ before(:each) do
54
+ @arv = Arv.new(:records, <<-ARV)
55
+ id = ID
56
+ age : 年齢
57
+ name = 名前
58
+ ARV
59
+ end
60
+
61
+ it "=がない行は無視される" do
62
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
63
+ <table class="arv-list records">
64
+ <thead>
65
+ <tr>
66
+ <th class='id' colspan=1>ID</th>
67
+ <th class='name' colspan=1>名前</th>
68
+ </tr>
69
+ </thead>
70
+ <%= collection_tbody_for(@records, %w( id name )) %>
71
+ </table>
72
+ ERB
73
+ end
74
+ end
75
+
76
+
77
+ describe ActiveRecordView::RenderArv, "#を含む場合" do
78
+ before(:each) do
79
+ @arv = Arv.new(:records, <<-ARV)
80
+ id = ID
81
+ # age = 年齢
82
+ name = 名前
83
+ ARV
84
+ end
85
+
86
+ it "先頭が#の行は無視される" do
87
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
88
+ <table class="arv-list records">
89
+ <thead>
90
+ <tr>
91
+ <th class='id' colspan=1>ID</th>
92
+ <th class='name' colspan=1>名前</th>
93
+ </tr>
94
+ </thead>
95
+ <%= collection_tbody_for(@records, %w( id name )) %>
96
+ </table>
97
+ ERB
98
+ end
99
+
100
+ it "= 以降に#がある行は有効" do
101
+ @arv.buffer = <<-ARV
102
+ id = ID
103
+ age = #年齢
104
+ name = 名前
105
+ ARV
106
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
107
+ <table class="arv-list records">
108
+ <thead>
109
+ <tr>
110
+ <th class='id' colspan=1>ID</th>
111
+ <th class='age' colspan=1>#年齢</th>
112
+ <th class='name' colspan=1>名前</th>
113
+ </tr>
114
+ </thead>
115
+ <%= collection_tbody_for(@records, %w( id age name )) %>
116
+ </table>
117
+ ERB
118
+ end
119
+ end
120
+
121
+
122
+ describe ActiveRecordView::RenderArv, "名称が空白の場合" do
123
+ before(:each) do
124
+ @arv = Arv.new(:records, <<-ARV)
125
+ id = ID
126
+ name = 名前
127
+ age =
128
+ ARV
129
+ end
130
+
131
+ it "最後の行が空白の場合、ひとつ前の名称がcolspan=2になる" do
132
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
133
+ <table class="arv-list records">
134
+ <thead>
135
+ <tr>
136
+ <th class='id' colspan=1>ID</th>
137
+ <th class='name' colspan=2>名前</th>
138
+ </tr>
139
+ </thead>
140
+ <%= collection_tbody_for(@records, %w( id name age )) %>
141
+ </table>
142
+ ERB
143
+ end
144
+
145
+ it "途中の行が空白の場合、ひとつ前の名称がcolspan=2になる" do
146
+ @arv.buffer = <<-ARV
147
+ id = ID
148
+ name =
149
+ age = 年齢
150
+ ARV
151
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
152
+ <table class="arv-list records">
153
+ <thead>
154
+ <tr>
155
+ <th class='id' colspan=2>ID</th>
156
+ <th class='age' colspan=1>年齢</th>
157
+ </tr>
158
+ </thead>
159
+ <%= collection_tbody_for(@records, %w( id name age )) %>
160
+ </table>
161
+ ERB
162
+ end
163
+
164
+ it "先頭の行が空白の場合、空白を無視して通常とおりcolspan=1として出力する" do
165
+ @arv.buffer = <<-ARV
166
+ id =
167
+ name = 名前
168
+ age = 年齢
169
+ ARV
170
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
171
+ <table class="arv-list records">
172
+ <thead>
173
+ <tr>
174
+ <th class='id' colspan=1></th>
175
+ <th class='name' colspan=1>名前</th>
176
+ <th class='age' colspan=1>年齢</th>
177
+ </tr>
178
+ </thead>
179
+ <%= collection_tbody_for(@records, %w( id name age )) %>
180
+ </table>
181
+ ERB
182
+ end
183
+
184
+ it "先頭と次の行が空白の場合、名前が空のcolspan=2が出力される" do
185
+ @arv.buffer = <<-ARV
186
+ id =
187
+ name =
188
+ age = 年齢
189
+ ARV
190
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
191
+ <table class="arv-list records">
192
+ <thead>
193
+ <tr>
194
+ <th class='id' colspan=2></th>
195
+ <th class='age' colspan=1>年齢</th>
196
+ </tr>
197
+ </thead>
198
+ <%= collection_tbody_for(@records, %w( id name age )) %>
199
+ </table>
200
+ ERB
201
+ end
202
+
203
+ it "3行とも全て場合、名前が空のcolspan=3が出力される" do
204
+ @arv.buffer = <<-ARV
205
+ id =
206
+ name =
207
+ age =
208
+ ARV
209
+ @arv.execute.should == (<<-ERB).gsub(/\n/, '')
210
+ <table class="arv-list records">
211
+ <thead>
212
+ <tr>
213
+ <th class='id' colspan=3></th>
214
+ </tr>
215
+ </thead>
216
+ <%= collection_tbody_for(@records, %w( id name age )) %>
217
+ </table>
218
+ ERB
219
+ end
220
+ end
data/spec/schema.rb ADDED
@@ -0,0 +1,30 @@
1
+ # This file is autogenerated. Instead of editing this file, please use the
2
+ # migrations feature of ActiveRecord to incrementally modify your database, and
3
+ # then regenerate this schema definition.
4
+
5
+ ActiveRecord::Schema.define(:version => 2) do
6
+
7
+ create_table "cards", :force => true do |t|
8
+ t.column "type", :string
9
+ t.column "no", :integer
10
+ t.column "name", :string
11
+ t.column "cost", :integer
12
+ t.column "kind", :string
13
+ t.column "hp", :integer
14
+ t.column "power", :integer
15
+ t.column "block", :integer
16
+ t.column "counter", :integer
17
+ t.column "capacity", :integer
18
+ t.column "skill_name", :string
19
+ t.column "skill_cost", :integer
20
+ t.column "member", :string
21
+ t.column "help", :string
22
+ end
23
+
24
+ create_table "decks", :force => true do |t|
25
+ t.column "name", :string
26
+ t.column "kind", :string
27
+ t.column "word", :string
28
+ end
29
+
30
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,27 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] = "test"
4
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
5
+ require 'spec/rails'
6
+
7
+ Spec::Runner.configure do |config|
8
+ config.use_transactional_fixtures = true
9
+ config.use_instantiated_fixtures = false
10
+ config.fixture_path = File.dirname(__FILE__) + '/fixtures'
11
+
12
+ # You can declare fixtures for each behaviour like this:
13
+ # describe "...." do
14
+ # fixtures :table_a, :table_b
15
+ #
16
+ # Alternatively, if you prefer to declare them only once, you can
17
+ # do so here, like so ...
18
+ #
19
+ # config.global_fixtures = :table_a, :table_b
20
+ #
21
+ # If you declare global fixtures, be aware that they will be declared
22
+ # for all of your examples, even those that don't use them.
23
+ end
24
+
25
+ Dependencies.load_paths << File.dirname(__FILE__) + '/fixtures'
26
+ Localized::Model.yaml_path = File.dirname(__FILE__) + "/localized"
27
+
@@ -0,0 +1,37 @@
1
+
2
+ def arv_file(name)
3
+ path = File.dirname(__FILE__) + "/../arv/#{name}"
4
+ File.read(path)
5
+ end
6
+
7
+ def enved_model
8
+ name = ENV["MODEL"].to_s
9
+ arv_fatal if name.blank?
10
+ returning name.constantize do |klass|
11
+ unless klass.ancestors.include?(ActiveRecord::Base)
12
+ arv_fatal("%s is not a subclass of ActiveRecord::Base" % klass)
13
+ end
14
+ end
15
+ end
16
+
17
+ def arv_fatal(message = nil)
18
+ puts message unless message.to_s.empty?
19
+ puts "specify AR model class name by 'MODEL' env"
20
+ puts " ex) rake arv:create:view MODEL=User"
21
+ exit
22
+ end
23
+
24
+ namespace "arv" do
25
+ task "create:view" => :environment do
26
+ require 'erb'
27
+ klass = enved_model
28
+ src = arv_file("property.erb")
29
+ erb = ERB.new(src, nil, '-')
30
+ yml = erb.result(binding)
31
+
32
+ dst = Pathname("%s/%s.yml" % [Localized::Model.yaml_path, klass.table_name]).cleanpath
33
+ dst.parent.mkpath
34
+ puts "writing YAML data to %s" % dst
35
+ File.open(dst, "w+") {|f| f.print yml}
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class ActiveRecordViewTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_this_plugin
6
+ flunk
7
+ end
8
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maiha-active_record_view
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - maiha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-03 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ""
17
+ email: maiha@wota.jp
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - Rakefile
27
+ - arv/properties/boolean
28
+ - arv/properties/date
29
+ - arv/properties/datetime
30
+ - arv/properties/default
31
+ - arv/properties/integer
32
+ - arv/properties/string
33
+ - arv/properties/text
34
+ - arv/properties/time
35
+ - arv/properties/timestamp
36
+ - arv/property.erb
37
+ - init.rb
38
+ - install.rb
39
+ - lib/active_record_view.rb
40
+ - lib/active_record_view/controller.rb
41
+ - lib/active_record_view/default_actions.rb
42
+ - lib/active_record_view/engines.rb
43
+ - lib/active_record_view/helper.rb
44
+ - lib/active_record_view/record_identifier.rb
45
+ - lib/active_record_view/render_arv.rb
46
+ - lib/active_record_view/write_exception.rb
47
+ - lib/localized/model.rb
48
+ - lib/localized/view_property.rb
49
+ - spec/fixtures/card.rb
50
+ - spec/fixtures/card/equip.rb
51
+ - spec/fixtures/card/magic.rb
52
+ - spec/fixtures/card/member.rb
53
+ - spec/fixtures/card/unit.rb
54
+ - spec/fixtures/deck.rb
55
+ - spec/localized/decks.yml
56
+ - spec/migrate/001_create_cards.rb
57
+ - spec/migrate/002_create_decks.rb
58
+ - spec/models/active_record_view_helper_spec.rb
59
+ - spec/models/render_spec.rb
60
+ - spec/schema.rb
61
+ - spec/spec.opts
62
+ - spec/spec_helper.rb
63
+ - tasks/active_record_view_tasks.rake
64
+ - test/active_record_view_test.rb
65
+ - uninstall.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/maiha/active_record_view
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.2.0
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: ""
92
+ test_files: []
93
+