toy-locomotive 0.0.7 → 0.0.8

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.
@@ -50,7 +50,7 @@ module ToyLocomotive::Attributes
50
50
  def to_helper
51
51
  return @_helper if @_helper
52
52
  return :text_area if @_as == :text
53
- return :hidden_field if @column == :id || @column.to_s[-3..-1] == '_id'
53
+ return :hidden_field if @column == :id || @_as == :belongs_to
54
54
  return :check_box if @column == :id || @_as == :boolean
55
55
  :text_field
56
56
  end
@@ -0,0 +1,27 @@
1
+ module ToyLocomotive::AutoViews
2
+ def auto_form_for args
3
+ form_for args do |f|
4
+ arg = args.class == Array ? args.last : args
5
+ klass = arg.class
6
+ html = ''
7
+ klass.attributes.each do |attr|
8
+ next if attr.skip_table_column?
9
+ if attr.to_helper == :hidden_field
10
+ html += f.send :hidden_field, attr.to_table_column
11
+ else
12
+ html += "<fieldset>"
13
+ html += f.label attr.to_table_column
14
+ html += f.send attr.to_helper, attr.to_table_column
15
+ html += "</fieldset>"
16
+ end
17
+ end
18
+ html += '<div class="actions">'
19
+ html += f.submit
20
+ html += link_to "Cancel", root_path
21
+ html += '</div>'
22
+ raw html
23
+ end.to_s
24
+ end
25
+ end
26
+
27
+ ActionView::Base.send :include, ToyLocomotive::AutoViews
@@ -0,0 +1,19 @@
1
+ module ToyLocomotive::AutoViews
2
+ def auto_show_for args
3
+ arg = args.class == Array ? args.last : args
4
+ klass = arg.class
5
+ html = '<div class="attributes-show">'
6
+ klass.attributes.each do |attr|
7
+ html += '<div class="attr-set">'
8
+ html += '<div class="attr-label">'+attr.column.to_s+'</div>'
9
+ html += '<div class="attr-content">'+arg.send(attr.column).to_s+'</div>'
10
+ html += '</div>'
11
+ end
12
+ html += '<div class="actions">'
13
+ html += link_to "Editar", {:action => :edit}, {:class => :edit}
14
+ html += link_to "Deletar", {:action => :destroy}, {:class => :destroy, :method => :delete, :confirm => "Tem certeza?"}
15
+ html += '</div>'
16
+ html += '</div>'
17
+ raw html
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module ToyLocomotive
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -6,6 +6,7 @@ module ToyLocomotive
6
6
  module Router; end
7
7
  module Resources; end
8
8
  module Attributes; end
9
+ module AutoViews; end
9
10
  mattr_accessor :routes
10
11
 
11
12
  end
@@ -16,4 +17,6 @@ require "toy-locomotive/resources/controller"
16
17
  require "toy-locomotive/attributes/chain"
17
18
  require "toy-locomotive/attributes/model"
18
19
  require "toy-locomotive/attributes/observer"
20
+ require "toy-locomotive/auto_views/show"
21
+ require "toy-locomotive/auto_views/form"
19
22
  require "toy-locomotive/initializer"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toy-locomotive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-11 00:00:00.000000000 Z
12
+ date: 2012-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &27219312 !ruby/object:Gem::Requirement
16
+ requirement: &26448552 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *27219312
24
+ version_requirements: *26448552
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-rails
27
- requirement: &27218736 !ruby/object:Gem::Requirement
27
+ requirement: &26446956 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *27218736
35
+ version_requirements: *26446956
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &27218244 !ruby/object:Gem::Requirement
38
+ requirement: &26446296 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *27218244
46
+ version_requirements: *26446296
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &27217476 !ruby/object:Gem::Requirement
49
+ requirement: &26445672 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *27217476
57
+ version_requirements: *26445672
58
58
  description: a Different aproach to Rails applications
59
59
  email:
60
60
  - mortaro@towsta.com
@@ -70,6 +70,8 @@ files:
70
70
  - lib/toy-locomotive/attributes/chain.rb
71
71
  - lib/toy-locomotive/attributes/model.rb
72
72
  - lib/toy-locomotive/attributes/observer.rb
73
+ - lib/toy-locomotive/auto_views/form.rb
74
+ - lib/toy-locomotive/auto_views/show.rb
73
75
  - lib/toy-locomotive/initializer.rb
74
76
  - lib/toy-locomotive/resources/controller.rb
75
77
  - lib/toy-locomotive/router/controller.rb