espresso 0.1.12 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +4 -2
  2. data/README.rdoc +18 -4
  3. data/Rakefile +33 -7
  4. data/VERSION +1 -1
  5. data/espresso.gemspec +59 -28
  6. data/lib/espresso.rb +36 -19
  7. data/lib/espresso/collection.rb +44 -0
  8. data/lib/espresso/collection/searchlogic.rb +17 -0
  9. data/lib/espresso/collection/will_paginate.rb +19 -0
  10. data/lib/espresso/concern.rb +37 -0
  11. data/lib/espresso/controller.rb +17 -0
  12. data/lib/espresso/controller/inherited_resources.rb +110 -0
  13. data/lib/espresso/deprecated.rb +19 -0
  14. data/lib/espresso/deprecated/resources.rb +11 -0
  15. data/lib/espresso/extensions/action_controller.rb +6 -0
  16. data/lib/espresso/extensions/action_view.rb +6 -0
  17. data/lib/espresso/extensions/active_record.rb +6 -0
  18. data/lib/espresso/extensions/all.rb +6 -0
  19. data/lib/espresso/{haml.rb → extensions/haml.rb} +4 -2
  20. data/lib/espresso/extensions/has_scope.rb +13 -0
  21. data/lib/espresso/extensions/inherited_resources.rb +15 -0
  22. data/lib/espresso/extensions/searchlogic.rb +14 -0
  23. data/lib/espresso/extensions/will_paginate.rb +14 -0
  24. data/lib/espresso/model.rb +22 -66
  25. data/lib/espresso/model/inherited_resources.rb +20 -0
  26. data/lib/espresso/view.rb +261 -0
  27. data/lib/espresso/{action_view → view}/form_builder.rb +3 -1
  28. data/lib/espresso/view/has_scope.rb +23 -0
  29. data/lib/espresso/view/inherited_resources.rb +72 -0
  30. data/lib/espresso/view/searchlogic.rb +33 -0
  31. data/lib/espresso/view/will_paginate.rb +35 -0
  32. data/test/espresso_collection_test.rb +6 -0
  33. data/test/espresso_controller_test.rb +1 -0
  34. data/test/espresso_extensions_haml_test.rb +19 -0
  35. data/test/espresso_model_test.rb +26 -0
  36. data/test/espresso_test.rb +1 -3
  37. data/test/espresso_view_has_scope_test.rb +11 -0
  38. data/test/espresso_view_test.rb +46 -0
  39. data/test/espresso_view_will_paginate_test.rb +9 -0
  40. data/test/example_model.rb +23 -0
  41. data/test/test_helper.rb +42 -1
  42. metadata +73 -33
  43. data/lib/espresso/action_controller.rb +0 -7
  44. data/lib/espresso/action_view.rb +0 -21
  45. data/lib/espresso/action_view/navigation.rb +0 -100
  46. data/lib/espresso/action_view/resources.rb +0 -59
  47. data/lib/espresso/action_view/scopes.rb +0 -38
  48. data/lib/espresso/action_view/stats.rb +0 -54
  49. data/lib/espresso/locales/en.yml +0 -6
  50. data/lib/espresso/locales/ru.yml +0 -11
  51. data/lib/espresso/resources.rb +0 -79
  52. data/lib/espresso/resources_helpers.rb +0 -24
@@ -1,7 +1,9 @@
1
+ require 'espresso/view'
2
+ require 'action_view'
1
3
  require 'formtastic'
2
4
 
3
5
  module Espresso
4
- module ActionView
6
+ module View
5
7
  class FormBuilder < Formtastic::SemanticFormBuilder
6
8
  def submit(value=nil, options={})
7
9
  value, options = nil, value if value.is_a?(Hash)
@@ -0,0 +1,23 @@
1
+ require 'espresso/view'
2
+ require 'has_scope'
3
+
4
+ module Espresso::View
5
+ mattr_accessor :scope_filter_wrapper_class, :scope_filter_ul_class
6
+ self.scope_filter_wrapper_class = 'b-scope-filter'
7
+ self.scope_filter_ul_class = 'b-hlist b-hlist_vline'
8
+
9
+ module InstanceMethods
10
+ def scope_filter(scopes)
11
+ content_tag(:div, :class => Espresso::View.scope_filter_wrapper_class) do
12
+ content_tag(:ul, :class => Espresso::View.scope_filter_ul_class) do
13
+ scopes.inject([]) do |list, scope|
14
+ list << content_tag(:li, link_to_unless_current(t(".#{scope}"),
15
+ collection_path(scope => true)))
16
+ list
17
+ end.join
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,72 @@
1
+ require 'espresso/view'
2
+ require 'inherited_resources'
3
+
4
+ module Espresso
5
+ module View
6
+ module InstanceMethods
7
+ def link_to_new(klass=nil, path=nil)
8
+ klass ||= resource_class
9
+ klass_underscored = klass.name.underscore
10
+ path ||= if klass == resource_class
11
+ new_resource_path
12
+ else
13
+ [:new, klass_underscored]
14
+ end
15
+ link_to(t("helpers.action.#{klass_underscored}.new",
16
+ :default => [:'helpers.action.new', 'Add']),
17
+ path,
18
+ :class => Espresso::View.block_classes('action', %w(new)))
19
+ rescue
20
+ end
21
+
22
+ def link_to_show(object=nil)
23
+ object ||= resource
24
+ link_to(t("helpers.action.#{object.class.name.underscore}.show",
25
+ :default => [:'helpers.action.show', object.to_s]),
26
+ object,
27
+ :class => Espresso::View.block_classes('action', %w(show)))
28
+ rescue
29
+ end
30
+
31
+ def link_to_edit(object=nil, path=nil)
32
+ object ||= resource
33
+ path ||= if object == resource
34
+ edit_resource_path
35
+ else
36
+ [:edit, object]
37
+ end
38
+ link_to(t("helpers.action.#{object.class.name.underscore}.edit",
39
+ :default => [:'helpers.action.edit', 'Edit']),
40
+ path,
41
+ :class => Espresso::View.block_classes('action', %w(edit)))
42
+ rescue
43
+ end
44
+
45
+ def link_to_destroy(object=nil, path=nil)
46
+ object ||= resource
47
+ path ||= if object == resource
48
+ resource_path
49
+ else
50
+ object
51
+ end
52
+ class_underscored = object.class.name.underscore
53
+ link_to(t("helpers.action.#{class_underscored}.edit",
54
+ :default => [:'helpers.action.destroy', 'Destroy']),
55
+ path,
56
+ :class => Espresso::View.block_classes('action', %w(destroy)),
57
+ :method => :delete,
58
+ :confirm => t("helpers.action.#{class_underscored}.confirm_destroy",
59
+ :default => [:'helpers.action.confirm_destroy', 'are you sure?']))
60
+ end
61
+
62
+ def link_to_index
63
+ link_to(t("helpers.action.#{controller_name.singularize}.index",
64
+ :default => [:'helpers.action.index', '&larr; Back']),
65
+ collection_path,
66
+ :class => 'b-action b-action_index')
67
+ rescue
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,33 @@
1
+ require 'espresso/view'
2
+ require 'searchlogic'
3
+
4
+ module Espresso::View
5
+ module InstanceMethods
6
+ def simple_search
7
+ ''.tap do |form|
8
+ form << form_tag(url_for(:action => :index), :method => :get)
9
+ form << content_tag(:table, :class => 'b-search') do
10
+ content_tag(:tr) do
11
+ ''.tap do |result|
12
+ result << content_tag(:td,
13
+ content_tag(:div,
14
+ text_field_tag(:q,
15
+ params[:q],
16
+ :type => 'search'),
17
+ :class => 'b-input'),
18
+ :class => 'input')
19
+ result << content_tag(:td,
20
+ submit_tag(t('espresso.view.find',
21
+ :default => 'Find!'),
22
+ :class => 'submit'),
23
+ :class => 'button')
24
+ end
25
+ end
26
+ end
27
+ form << yield if block_given?
28
+ form << '</form>'
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'espresso/view'
2
+ require 'will_paginate/view_helpers'
3
+
4
+ module Espresso::View
5
+ module InstanceMethods
6
+ include WillPaginate::ViewHelpers
7
+
8
+ def will_paginate_with_i18n(collection, options = {})
9
+ will_paginate_without_i18n(collection,
10
+ options.merge({
11
+ :class => 'b-pagination',
12
+ :previous_label => t('espresso.navigation.previous', :default => '← Previous'),
13
+ :next_label => t('espresso.navigation.next', :default => 'Next →')}))
14
+ end
15
+ alias_method_chain :will_paginate, :i18n
16
+
17
+ def paginated_list(collection_name, options = {})
18
+ collection = options.delete(:collection) do
19
+ instance_variable_get("@#{collection_name}")
20
+ end
21
+ prefix = options.delete(:prefix)
22
+ prefix = prefix ? " b-list_#{prefix}_#{collection_name}" : nil
23
+ start = (collection.respond_to?(:offset) ? collection.offset : 0) + 1
24
+ ''.tap do |result|
25
+ result << content_tag(:ol,
26
+ render(collection),
27
+ :class => "b-list b-list_#{collection_name}#{prefix}",
28
+ :start => start)
29
+ if collection.respond_to?(:total_pages)
30
+ result << (will_paginate(collection, options) || '')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+ require 'espresso/collection'
3
+
4
+ class Espresso::CollectionTest < Test::Unit::TestCase
5
+ should_have_instance_methods(:search, :to_a) { Espresso::Collection.new(nil) }
6
+ end
@@ -0,0 +1 @@
1
+ require 'test_helper'
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ require 'espresso/extensions/haml'
3
+ require 'example_model'
4
+
5
+ class Haml::BufferTest < Test::Unit::TestCase
6
+ context 'Haml::Buffer instance' do
7
+ setup { @buffer = Haml::Buffer.new }
8
+
9
+ {
10
+ [ExampleModel.new(1)] => {'id' => 'example_model_1', 'class' => 'b-example-model'},
11
+ [NonModel.new, :prefix] => {'id' => 'prefix_non_model_6', 'class' => 'prefix_non_model'},
12
+ [ExampleModel.new(5, true)] => {'id' => 'example_model_5', 'class' => 'b-example-model b-example-model_safe'}
13
+ }.each do |ref, result|
14
+ should "parse #{ref.inspect} ref to #{result.inspect} " do
15
+ assert_equal(result, @buffer.parse_object_ref(ref))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+ require 'example_model'
3
+
4
+ class ExampleModelTest < Test::Unit::TestCase
5
+ should_have_class_methods :make_slug
6
+ should_have_instance_methods :to_s
7
+
8
+ {
9
+ 'Foo Bar' => 'foo-bar',
10
+ 'Baz Bar Foo' => 'baz-bar-foo'
11
+ }.each do |name, slug|
12
+ context "Example instance with name '#{name}'" do
13
+ setup {
14
+ @example = ExampleModel.new
15
+ @example.name = name
16
+ }
17
+
18
+ should "represents to_s as '#{name}'" do
19
+ assert_equal name, @example.to_s
20
+ end
21
+ should "make slug '#{slug}'" do
22
+ assert_equal slug, ExampleModel.make_slug(@example)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class EspressoTest < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
4
+ should_have_class_methods :configure, :uses, :extensions
7
5
  end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+ require 'action_controller'
3
+ require 'espresso/view/has_scope'
4
+
5
+
6
+ class Espresso::ViewTest < Test::Unit::TestCase
7
+ include Espresso::View
8
+
9
+ should_have_class_methods :scope_filter_wrapper_class, :scope_filter_ul_class
10
+ should_have_instance_methods :scope_filter
11
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+ require 'espresso/view'
3
+
4
+ class Espresso::ViewTest < Test::Unit::TestCase
5
+ include Espresso::View
6
+
7
+ should_have_class_methods :block_prefix, :block_classes
8
+ should_have_instance_methods :model_classes, :view_name,
9
+ :default_page_title, :page_title, :head_title, :navigation_list,
10
+ :overwrite_url, :overwrite_path, :online_stats, :body_modifiers,
11
+ :time, :date
12
+
13
+ {
14
+ 'b-example' => ['example'],
15
+ 'b-example b-example_foo' => ['example', %w(foo)],
16
+ 'b-example b-example_foo b-example_bar' => ['example', %w(foo bar)],
17
+ 'o-example' => ['example', [], {:type => 'o'}],
18
+ 'y-example y-example_foo y-example_bar y-example_baz' => ['example', %w(foo bar baz), {:type => 'y'}],
19
+ }.each do |result, params|
20
+ should "build '#{result}' from #{params.inspect}" do
21
+ assert_equal result, Espresso::View.block_classes(*params)
22
+ end
23
+ end
24
+
25
+ class Example
26
+ def self.model_modifiers
27
+ [:foo]
28
+ end
29
+ end
30
+
31
+ class ::FooExample < Example
32
+ def foo?
33
+ true
34
+ end
35
+ end
36
+
37
+ should 'build "b-espresso-view-test-example" from Example instance' do
38
+ @example = Example.new
39
+ assert_equal 'b-espresso-view-test-example', model_classes(@example)
40
+ end
41
+
42
+ should 'build "b-foo-example b-foo-example_foo" from FooExample instance' do
43
+ @example = FooExample.new
44
+ assert_equal 'b-foo-example b-foo-example_foo', model_classes(@example)
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'espresso/view/will_paginate'
3
+
4
+
5
+ class Espresso::ViewTest < Test::Unit::TestCase
6
+ include Espresso::View
7
+
8
+ should_have_instance_methods :will_paginate, :paginated_list
9
+ end
@@ -0,0 +1,23 @@
1
+ require 'espresso/model'
2
+
3
+ class ExampleModel
4
+ include Espresso::Model
5
+ self.model_modifiers << :safe
6
+
7
+ attr_accessor :id, :name, :safe
8
+
9
+ def initialize(id = nil, safe = false)
10
+ self.id = id
11
+ self.safe = safe
12
+ end
13
+
14
+ def safe?
15
+ safe == true
16
+ end
17
+ end
18
+
19
+ class NonModel
20
+ def id
21
+ 6
22
+ end
23
+ end
@@ -1,10 +1,51 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'redgreen'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
8
  require 'espresso'
8
9
 
9
- class Test::Unit::TestCase
10
+ require 'active_support/core_ext/string'
11
+ module Test
12
+ module Unit
13
+ class TestCase
14
+ def self.should_have_class_methods(*methods)
15
+ get_options!(methods)
16
+ klass = described_type
17
+ methods.each do |method|
18
+ should "respond to class method ##{method}" do
19
+ assert_respond_to(klass, method, "#{klass.name} does not have class method #{method}")
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.should_have_instance_methods(*methods)
25
+ get_options!(methods)
26
+ klass = described_type
27
+ instance = if block_given?
28
+ # Class initializer requires some attributes,
29
+ # or another custom generator used
30
+ yield
31
+ elsif klass.is_a?(Class)
32
+ klass.new
33
+ else
34
+ # klass is a module
35
+ metaclass = Class.new
36
+ metaclass.send(:include, klass)
37
+ metaclass.new
38
+ end
39
+ methods.each do |method|
40
+ should "respond to instance method ##{method}" do
41
+ assert_respond_to(instance, method, "#{klass.name} does not have instance method #{method}")
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ class TestCaseTest < TestCase
48
+ should_have_class_methods :should_have_class_methods, :should_have_instance_methods
49
+ end
50
+ end
10
51
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 2
7
8
  - 1
8
- - 12
9
- version: 0.1.12
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexander Semyonov
@@ -14,63 +14,63 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-25 00:00:00 +03:00
17
+ date: 2010-03-29 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: searchlogic
21
+ name: activesupport
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 2
29
- - 2
30
29
  - 3
31
- version: 2.2.3
30
+ - 5
31
+ version: 2.3.5
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: inherited_resources
35
+ name: activerecord
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
- - 0
43
- - 8
42
+ - 2
43
+ - 3
44
44
  - 5
45
- version: 0.8.5
45
+ version: 2.3.5
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: will_paginate
49
+ name: actionpack
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  segments:
56
56
  - 2
57
57
  - 3
58
- - 11
59
- version: 2.3.11
58
+ - 5
59
+ version: 2.3.5
60
60
  type: :runtime
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- name: formtastic
63
+ name: inherited_resources
64
64
  prerelease: false
65
65
  requirement: &id004 !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  segments:
70
+ - 1
70
71
  - 0
71
- - 9
72
- - 7
73
- version: 0.9.7
72
+ - 5
73
+ version: 1.0.5
74
74
  type: :runtime
75
75
  version_requirements: *id004
76
76
  - !ruby/object:Gem::Dependency
@@ -85,6 +85,18 @@ dependencies:
85
85
  version: "0"
86
86
  type: :development
87
87
  version_requirements: *id005
88
+ - !ruby/object:Gem::Dependency
89
+ name: redgreen
90
+ prerelease: false
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ type: :development
99
+ version_requirements: *id006
88
100
  description: Useful templates for controller and model functions
89
101
  email: rotuka@tokak.ru
90
102
  executables: []
@@ -103,20 +115,40 @@ files:
103
115
  - espresso.gemspec
104
116
  - init.rb
105
117
  - lib/espresso.rb
106
- - lib/espresso/action_controller.rb
107
- - lib/espresso/action_view.rb
108
- - lib/espresso/action_view/form_builder.rb
109
- - lib/espresso/action_view/navigation.rb
110
- - lib/espresso/action_view/resources.rb
111
- - lib/espresso/action_view/scopes.rb
112
- - lib/espresso/action_view/stats.rb
113
- - lib/espresso/haml.rb
114
- - lib/espresso/locales/en.yml
115
- - lib/espresso/locales/ru.yml
118
+ - lib/espresso/collection.rb
119
+ - lib/espresso/collection/searchlogic.rb
120
+ - lib/espresso/collection/will_paginate.rb
121
+ - lib/espresso/concern.rb
122
+ - lib/espresso/controller.rb
123
+ - lib/espresso/controller/inherited_resources.rb
124
+ - lib/espresso/deprecated.rb
125
+ - lib/espresso/deprecated/resources.rb
126
+ - lib/espresso/extensions/action_controller.rb
127
+ - lib/espresso/extensions/action_view.rb
128
+ - lib/espresso/extensions/active_record.rb
129
+ - lib/espresso/extensions/all.rb
130
+ - lib/espresso/extensions/haml.rb
131
+ - lib/espresso/extensions/has_scope.rb
132
+ - lib/espresso/extensions/inherited_resources.rb
133
+ - lib/espresso/extensions/searchlogic.rb
134
+ - lib/espresso/extensions/will_paginate.rb
116
135
  - lib/espresso/model.rb
117
- - lib/espresso/resources.rb
118
- - lib/espresso/resources_helpers.rb
136
+ - lib/espresso/model/inherited_resources.rb
137
+ - lib/espresso/view.rb
138
+ - lib/espresso/view/form_builder.rb
139
+ - lib/espresso/view/has_scope.rb
140
+ - lib/espresso/view/inherited_resources.rb
141
+ - lib/espresso/view/searchlogic.rb
142
+ - lib/espresso/view/will_paginate.rb
143
+ - test/espresso_collection_test.rb
144
+ - test/espresso_controller_test.rb
145
+ - test/espresso_extensions_haml_test.rb
146
+ - test/espresso_model_test.rb
119
147
  - test/espresso_test.rb
148
+ - test/espresso_view_has_scope_test.rb
149
+ - test/espresso_view_test.rb
150
+ - test/espresso_view_will_paginate_test.rb
151
+ - test/example_model.rb
120
152
  - test/test_helper.rb
121
153
  has_rdoc: true
122
154
  homepage: http://github.com/krasivotokak/espresso
@@ -149,5 +181,13 @@ signing_key:
149
181
  specification_version: 3
150
182
  summary: Rails extender to simplify rails development
151
183
  test_files:
184
+ - test/espresso_extensions_haml_test.rb
185
+ - test/example_model.rb
186
+ - test/espresso_collection_test.rb
187
+ - test/espresso_model_test.rb
188
+ - test/espresso_view_test.rb
152
189
  - test/espresso_test.rb
153
190
  - test/test_helper.rb
191
+ - test/espresso_controller_test.rb
192
+ - test/espresso_view_has_scope_test.rb
193
+ - test/espresso_view_will_paginate_test.rb