espresso 0.1.12 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -2
- data/README.rdoc +18 -4
- data/Rakefile +33 -7
- data/VERSION +1 -1
- data/espresso.gemspec +59 -28
- data/lib/espresso.rb +36 -19
- data/lib/espresso/collection.rb +44 -0
- data/lib/espresso/collection/searchlogic.rb +17 -0
- data/lib/espresso/collection/will_paginate.rb +19 -0
- data/lib/espresso/concern.rb +37 -0
- data/lib/espresso/controller.rb +17 -0
- data/lib/espresso/controller/inherited_resources.rb +110 -0
- data/lib/espresso/deprecated.rb +19 -0
- data/lib/espresso/deprecated/resources.rb +11 -0
- data/lib/espresso/extensions/action_controller.rb +6 -0
- data/lib/espresso/extensions/action_view.rb +6 -0
- data/lib/espresso/extensions/active_record.rb +6 -0
- data/lib/espresso/extensions/all.rb +6 -0
- data/lib/espresso/{haml.rb → extensions/haml.rb} +4 -2
- data/lib/espresso/extensions/has_scope.rb +13 -0
- data/lib/espresso/extensions/inherited_resources.rb +15 -0
- data/lib/espresso/extensions/searchlogic.rb +14 -0
- data/lib/espresso/extensions/will_paginate.rb +14 -0
- data/lib/espresso/model.rb +22 -66
- data/lib/espresso/model/inherited_resources.rb +20 -0
- data/lib/espresso/view.rb +261 -0
- data/lib/espresso/{action_view → view}/form_builder.rb +3 -1
- data/lib/espresso/view/has_scope.rb +23 -0
- data/lib/espresso/view/inherited_resources.rb +72 -0
- data/lib/espresso/view/searchlogic.rb +33 -0
- data/lib/espresso/view/will_paginate.rb +35 -0
- data/test/espresso_collection_test.rb +6 -0
- data/test/espresso_controller_test.rb +1 -0
- data/test/espresso_extensions_haml_test.rb +19 -0
- data/test/espresso_model_test.rb +26 -0
- data/test/espresso_test.rb +1 -3
- data/test/espresso_view_has_scope_test.rb +11 -0
- data/test/espresso_view_test.rb +46 -0
- data/test/espresso_view_will_paginate_test.rb +9 -0
- data/test/example_model.rb +23 -0
- data/test/test_helper.rb +42 -1
- metadata +73 -33
- data/lib/espresso/action_controller.rb +0 -7
- data/lib/espresso/action_view.rb +0 -21
- data/lib/espresso/action_view/navigation.rb +0 -100
- data/lib/espresso/action_view/resources.rb +0 -59
- data/lib/espresso/action_view/scopes.rb +0 -38
- data/lib/espresso/action_view/stats.rb +0 -54
- data/lib/espresso/locales/en.yml +0 -6
- data/lib/espresso/locales/ru.yml +0 -11
- data/lib/espresso/resources.rb +0 -79
- data/lib/espresso/resources_helpers.rb +0 -24
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
-
=
|
1
|
+
= Espresso
|
2
2
|
|
3
|
-
|
3
|
+
Some useful extensions to default Rails environment.
|
4
|
+
|
5
|
+
Can be more extended if using with InheritedResources, WillPaginate, Searchlogic and Formtastic.
|
6
|
+
|
7
|
+
== Espresso::Model
|
8
|
+
|
9
|
+
Enhances ActiveRecord::Base classes with #name_field and #make_slug methods.
|
10
|
+
|
11
|
+
== Espresso::View
|
12
|
+
|
13
|
+
Enhances ActionView with some useful helpers
|
14
|
+
|
15
|
+
== Espresso::Controller
|
16
|
+
|
17
|
+
Uses InheritedResources, WillPaginate and Searchlogic to provide enhanced RESTful resources controllers.
|
4
18
|
|
5
19
|
== Note on Patches/Pull Requests
|
6
|
-
|
20
|
+
|
7
21
|
* Fork the project.
|
8
22
|
* Make your feature addition or bug fix.
|
9
23
|
* Add tests for it. This is important so I don't break it in a
|
@@ -15,4 +29,4 @@ Description goes here.
|
|
15
29
|
|
16
30
|
== Copyright
|
17
31
|
|
18
|
-
|
32
|
+
© 2009 Alexander Semyonov. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -10,11 +10,12 @@ begin
|
|
10
10
|
gem.email = 'rotuka@tokak.ru'
|
11
11
|
gem.homepage = 'http://github.com/krasivotokak/espresso'
|
12
12
|
gem.authors = ['Alexander Semyonov']
|
13
|
-
gem.add_dependency('
|
14
|
-
gem.add_dependency('
|
15
|
-
gem.add_dependency('
|
16
|
-
gem.add_dependency('
|
13
|
+
gem.add_dependency('activesupport', '~> 2.3.5')
|
14
|
+
gem.add_dependency('activerecord', '~> 2.3.5')
|
15
|
+
gem.add_dependency('actionpack', '~> 2.3.5')
|
16
|
+
gem.add_dependency('inherited_resources', '~> 1.0.5')
|
17
17
|
gem.add_development_dependency('shoulda')
|
18
|
+
gem.add_development_dependency('redgreen')
|
18
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
20
|
end
|
20
21
|
Jeweler::GemcutterTasks.new
|
@@ -32,13 +33,36 @@ end
|
|
32
33
|
begin
|
33
34
|
require 'rcov/rcovtask'
|
34
35
|
Rcov::RcovTask.new do |test|
|
35
|
-
test.libs << 'test'
|
36
|
+
test.libs << 'lib' << 'test'
|
36
37
|
test.pattern = 'test/**/*_test.rb'
|
37
38
|
test.verbose = true
|
38
39
|
end
|
39
40
|
rescue LoadError
|
40
41
|
task :rcov do
|
41
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install
|
42
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
require 'reek/rake/task'
|
48
|
+
Reek::Rake::Task.new do |test|
|
49
|
+
test.ruby_opts << '-rubygems'
|
50
|
+
end
|
51
|
+
rescue LoadError
|
52
|
+
task :reek do
|
53
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
begin
|
58
|
+
require 'roodi'
|
59
|
+
require 'roodi_task'
|
60
|
+
RoodiTask.new do |t|
|
61
|
+
t.patterns << 'lib/*.rb' << 'lib/**/*.rb'
|
62
|
+
end
|
63
|
+
rescue LoadError
|
64
|
+
task :roodi do
|
65
|
+
abort "Roodi is not available. In order to run reek, you must: sudo gem install roodi"
|
42
66
|
end
|
43
67
|
end
|
44
68
|
|
@@ -48,7 +72,9 @@ task :default => :test
|
|
48
72
|
|
49
73
|
begin
|
50
74
|
require 'yard'
|
51
|
-
YARD::Rake::YardocTask.new
|
75
|
+
YARD::Rake::YardocTask.new do |yard|
|
76
|
+
yard.options << '--no-private'
|
77
|
+
end
|
52
78
|
rescue LoadError
|
53
79
|
task :yardoc do
|
54
80
|
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1
|
1
|
+
0.2.1
|
data/espresso.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{espresso}
|
8
|
-
s.version = "0.1
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexander Semyonov"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-29}
|
13
13
|
s.description = %q{Useful templates for controller and model functions}
|
14
14
|
s.email = %q{rotuka@tokak.ru}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,20 +25,40 @@ Gem::Specification.new do |s|
|
|
25
25
|
"espresso.gemspec",
|
26
26
|
"init.rb",
|
27
27
|
"lib/espresso.rb",
|
28
|
-
"lib/espresso/
|
29
|
-
"lib/espresso/
|
30
|
-
"lib/espresso/
|
31
|
-
"lib/espresso/
|
32
|
-
"lib/espresso/
|
33
|
-
"lib/espresso/
|
34
|
-
"lib/espresso/
|
35
|
-
"lib/espresso/
|
36
|
-
"lib/espresso/
|
37
|
-
"lib/espresso/
|
28
|
+
"lib/espresso/collection.rb",
|
29
|
+
"lib/espresso/collection/searchlogic.rb",
|
30
|
+
"lib/espresso/collection/will_paginate.rb",
|
31
|
+
"lib/espresso/concern.rb",
|
32
|
+
"lib/espresso/controller.rb",
|
33
|
+
"lib/espresso/controller/inherited_resources.rb",
|
34
|
+
"lib/espresso/deprecated.rb",
|
35
|
+
"lib/espresso/deprecated/resources.rb",
|
36
|
+
"lib/espresso/extensions/action_controller.rb",
|
37
|
+
"lib/espresso/extensions/action_view.rb",
|
38
|
+
"lib/espresso/extensions/active_record.rb",
|
39
|
+
"lib/espresso/extensions/all.rb",
|
40
|
+
"lib/espresso/extensions/haml.rb",
|
41
|
+
"lib/espresso/extensions/has_scope.rb",
|
42
|
+
"lib/espresso/extensions/inherited_resources.rb",
|
43
|
+
"lib/espresso/extensions/searchlogic.rb",
|
44
|
+
"lib/espresso/extensions/will_paginate.rb",
|
38
45
|
"lib/espresso/model.rb",
|
39
|
-
"lib/espresso/
|
40
|
-
"lib/espresso/
|
46
|
+
"lib/espresso/model/inherited_resources.rb",
|
47
|
+
"lib/espresso/view.rb",
|
48
|
+
"lib/espresso/view/form_builder.rb",
|
49
|
+
"lib/espresso/view/has_scope.rb",
|
50
|
+
"lib/espresso/view/inherited_resources.rb",
|
51
|
+
"lib/espresso/view/searchlogic.rb",
|
52
|
+
"lib/espresso/view/will_paginate.rb",
|
53
|
+
"test/espresso_collection_test.rb",
|
54
|
+
"test/espresso_controller_test.rb",
|
55
|
+
"test/espresso_extensions_haml_test.rb",
|
56
|
+
"test/espresso_model_test.rb",
|
41
57
|
"test/espresso_test.rb",
|
58
|
+
"test/espresso_view_has_scope_test.rb",
|
59
|
+
"test/espresso_view_test.rb",
|
60
|
+
"test/espresso_view_will_paginate_test.rb",
|
61
|
+
"test/example_model.rb",
|
42
62
|
"test/test_helper.rb"
|
43
63
|
]
|
44
64
|
s.homepage = %q{http://github.com/krasivotokak/espresso}
|
@@ -47,8 +67,16 @@ Gem::Specification.new do |s|
|
|
47
67
|
s.rubygems_version = %q{1.3.6}
|
48
68
|
s.summary = %q{Rails extender to simplify rails development}
|
49
69
|
s.test_files = [
|
50
|
-
"test/
|
51
|
-
"test/
|
70
|
+
"test/espresso_extensions_haml_test.rb",
|
71
|
+
"test/example_model.rb",
|
72
|
+
"test/espresso_collection_test.rb",
|
73
|
+
"test/espresso_model_test.rb",
|
74
|
+
"test/espresso_view_test.rb",
|
75
|
+
"test/espresso_test.rb",
|
76
|
+
"test/test_helper.rb",
|
77
|
+
"test/espresso_controller_test.rb",
|
78
|
+
"test/espresso_view_has_scope_test.rb",
|
79
|
+
"test/espresso_view_will_paginate_test.rb"
|
52
80
|
]
|
53
81
|
|
54
82
|
if s.respond_to? :specification_version then
|
@@ -56,24 +84,27 @@ Gem::Specification.new do |s|
|
|
56
84
|
s.specification_version = 3
|
57
85
|
|
58
86
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
-
s.add_runtime_dependency(%q<
|
60
|
-
s.add_runtime_dependency(%q<
|
61
|
-
s.add_runtime_dependency(%q<
|
62
|
-
s.add_runtime_dependency(%q<
|
87
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 2.3.5"])
|
88
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 2.3.5"])
|
89
|
+
s.add_runtime_dependency(%q<actionpack>, ["~> 2.3.5"])
|
90
|
+
s.add_runtime_dependency(%q<inherited_resources>, ["~> 1.0.5"])
|
63
91
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
92
|
+
s.add_development_dependency(%q<redgreen>, [">= 0"])
|
64
93
|
else
|
65
|
-
s.add_dependency(%q<
|
66
|
-
s.add_dependency(%q<
|
67
|
-
s.add_dependency(%q<
|
68
|
-
s.add_dependency(%q<
|
94
|
+
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
95
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.5"])
|
96
|
+
s.add_dependency(%q<actionpack>, ["~> 2.3.5"])
|
97
|
+
s.add_dependency(%q<inherited_resources>, ["~> 1.0.5"])
|
69
98
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
99
|
+
s.add_dependency(%q<redgreen>, [">= 0"])
|
70
100
|
end
|
71
101
|
else
|
72
|
-
s.add_dependency(%q<
|
73
|
-
s.add_dependency(%q<
|
74
|
-
s.add_dependency(%q<
|
75
|
-
s.add_dependency(%q<
|
102
|
+
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
103
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.5"])
|
104
|
+
s.add_dependency(%q<actionpack>, ["~> 2.3.5"])
|
105
|
+
s.add_dependency(%q<inherited_resources>, ["~> 1.0.5"])
|
76
106
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
107
|
+
s.add_dependency(%q<redgreen>, [">= 0"])
|
77
108
|
end
|
78
109
|
end
|
79
110
|
|
data/lib/espresso.rb
CHANGED
@@ -1,32 +1,49 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
$KCODE = 'u'
|
2
|
+
require 'active_support/core_ext/module'
|
3
3
|
|
4
|
+
module Espresso
|
4
5
|
autoload :Model, 'espresso/model'
|
5
|
-
autoload :
|
6
|
-
autoload :
|
7
|
-
autoload :
|
8
|
-
autoload :
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
autoload :View, 'espresso/view'
|
7
|
+
autoload :Controller, 'espresso/controller'
|
8
|
+
autoload :Collection, 'espresso/collection'
|
9
|
+
autoload :Concern, 'espresso/concern'
|
10
|
+
|
11
|
+
BASE_MODULES = %w(model view controller)
|
12
|
+
|
13
|
+
mattr_accessor :extensions
|
14
|
+
self.extensions = []
|
15
|
+
|
16
|
+
# Configures Espresso.
|
17
|
+
# By default, loads all extensions
|
18
|
+
def self.configure
|
19
|
+
if block_given?
|
20
|
+
yield
|
21
|
+
else
|
22
|
+
uses :all
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Loads Espresso extensions
|
27
|
+
# @param [String, Symbol] extension name of the Espresso extension
|
28
|
+
def self.uses(extension)
|
29
|
+
require("espresso/extensions/#{extension}")
|
13
30
|
end
|
14
31
|
end
|
15
32
|
|
16
33
|
if defined?(ActiveRecord)
|
17
|
-
|
34
|
+
Espresso.uses :active_record
|
18
35
|
end
|
19
36
|
|
20
|
-
if defined?(
|
21
|
-
|
22
|
-
ActionController::Base.extend(Espresso::ActionController)
|
37
|
+
if defined?(ActionView)
|
38
|
+
Espresso.uses :action_view
|
23
39
|
end
|
24
40
|
|
25
|
-
if defined?(
|
26
|
-
|
41
|
+
if defined?(ActionController)
|
42
|
+
Espresso.uses :action_controller
|
27
43
|
end
|
28
44
|
|
29
|
-
|
30
|
-
|
45
|
+
if defined?(Haml)
|
46
|
+
Espresso.uses :haml
|
47
|
+
end
|
31
48
|
|
32
|
-
require 'espresso/
|
49
|
+
require 'espresso/deprecated'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'active_support/core_ext/class'
|
2
|
+
|
3
|
+
module Espresso
|
4
|
+
self.extensions << :collection
|
5
|
+
# Represents collection of resources.
|
6
|
+
# Used in Espresso::Controller InheritedResources extension
|
7
|
+
class Collection < Array
|
8
|
+
cattr_accessor :per_page
|
9
|
+
self.per_page = 30
|
10
|
+
|
11
|
+
attr_accessor :base, :options, :collection, :search
|
12
|
+
protected :base, :options, :collection
|
13
|
+
|
14
|
+
# Initiates a collection of resources
|
15
|
+
# @param [AtiveRecord::Base] base Base class having {Espresso::Model} included
|
16
|
+
# @param [Hash] options options for building the collection
|
17
|
+
# @option options [Number] :page current page number
|
18
|
+
# @option options [Number] :per_page per-page limit
|
19
|
+
# @option options [Hash] :search conditions for searching
|
20
|
+
def initialize(base, options = {})
|
21
|
+
@base, @options = base, options
|
22
|
+
replace(collection)
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
# All resources in {#base}
|
27
|
+
def collection
|
28
|
+
@collection ||= base.all(@options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Proxy to {#collection} methods
|
32
|
+
def method_missing(method_name, *args)
|
33
|
+
collection.send(method_name, *args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if defined? Searchlogic
|
39
|
+
require 'espresso/collection/searchlogic'
|
40
|
+
end
|
41
|
+
|
42
|
+
if defined? WillPaginate
|
43
|
+
require 'espresso/collection/will_paginate'
|
44
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'espresso/collection'
|
2
|
+
require 'searchlogic'
|
3
|
+
|
4
|
+
module Espresso
|
5
|
+
class Collection
|
6
|
+
# Use ActiveRecord::Base#searchlogic method to generate
|
7
|
+
# base for finding the collection
|
8
|
+
# @return [ActiveRecord::Base] ActiveRecord model scoped with searchlogic
|
9
|
+
def base
|
10
|
+
unless @search
|
11
|
+
search_options = options.delete(:search) { {} }
|
12
|
+
@search = @base.searchlogic(search_options)
|
13
|
+
end
|
14
|
+
@search
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'espresso/collection'
|
2
|
+
require 'will_paginate/collection'
|
3
|
+
|
4
|
+
module Espresso
|
5
|
+
class Collection
|
6
|
+
# Finds collection by ActiveRecord::Base.paginate method
|
7
|
+
# and options provided in {Espresso::Collection#initialize} method
|
8
|
+
# @return [WillPaginate::Collection] single page of resources
|
9
|
+
def collection
|
10
|
+
unless @collection
|
11
|
+
page = options.delete(:page) { 1 }
|
12
|
+
per_page = options.delete(:per_page) { Espresso::Collection.per_page }
|
13
|
+
@collection ||= base.paginate(:page => page,
|
14
|
+
:per_page => per_page)
|
15
|
+
end
|
16
|
+
@collection
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'espresso'
|
2
|
+
|
3
|
+
module Espresso
|
4
|
+
# Code extracted from ActiveSupport 3.0.0beta
|
5
|
+
module Concern
|
6
|
+
def self.extended(base)
|
7
|
+
base.instance_variable_set('@_dependencies', [])
|
8
|
+
end
|
9
|
+
|
10
|
+
def append_features(base)
|
11
|
+
if base.instance_variable_defined?('@_dependencies')
|
12
|
+
base.instance_variable_get('@_dependencies') << self
|
13
|
+
return false
|
14
|
+
else
|
15
|
+
return false if base < self
|
16
|
+
@_dependencies.each { |dep| base.send(:include, dep) }
|
17
|
+
super
|
18
|
+
base.extend const_get('ClassMethods') if const_defined?('ClassMethods')
|
19
|
+
base.send :include, const_get('InstanceMethods') if const_defined?('InstanceMethods')
|
20
|
+
if instance_variable_defined?('@_included_blocks')
|
21
|
+
@_included_blocks.each do |included_block|
|
22
|
+
base.class_eval(&included_block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def included(base = nil, &block)
|
29
|
+
if base.nil?
|
30
|
+
@_included_blocks ||= []
|
31
|
+
@_included_blocks << block
|
32
|
+
else
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'espresso'
|
2
|
+
|
3
|
+
module Espresso
|
4
|
+
module Controller
|
5
|
+
extend Espresso::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if defined?(InheritedResources)
|
16
|
+
require 'espresso/controller/inherited_resources'
|
17
|
+
end
|