krasivotokak-espresso 0.0.1
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.
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/espresso.gemspec +60 -0
- data/init.rb +4 -0
- data/lib/espresso/controller.rb +26 -0
- data/lib/espresso/model.rb +48 -0
- data/lib/espresso.rb +2 -0
- data/test/espresso_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +95 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alexander Semyonov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= espresso
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Alexander Semyonov. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "espresso"
|
8
|
+
gem.summary = %Q{Rails extender to simplify rails development}
|
9
|
+
gem.description = %Q{Useful templates for controller and model functions}
|
10
|
+
gem.email = "rotuka@rotuka.com"
|
11
|
+
gem.homepage = "http://github.com/krasivotokak/espresso"
|
12
|
+
gem.authors = ["Alexander Semyonov"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
+
gem.add_dependency('searchlogic', '>= 2.2.3')
|
15
|
+
gem.add_dependency('josevalim-inherited_resources', '>= 0.8.5')
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/*_test.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/*_test.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
if File.exist?('VERSION')
|
49
|
+
version = File.read('VERSION')
|
50
|
+
else
|
51
|
+
version = ""
|
52
|
+
end
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "espresso #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/espresso.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{espresso}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alexander Semyonov"]
|
12
|
+
s.date = %q{2009-08-15}
|
13
|
+
s.description = %q{Useful templates for controller and model functions}
|
14
|
+
s.email = %q{rotuka@rotuka.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"LICENSE",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"espresso.gemspec",
|
25
|
+
"init.rb",
|
26
|
+
"lib/espresso.rb",
|
27
|
+
"lib/espresso/controller.rb",
|
28
|
+
"lib/espresso/model.rb",
|
29
|
+
"test/espresso_test.rb",
|
30
|
+
"test/test_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/krasivotokak/espresso}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.5}
|
36
|
+
s.summary = %q{Rails extender to simplify rails development}
|
37
|
+
s.test_files = [
|
38
|
+
"test/espresso_test.rb",
|
39
|
+
"test/test_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
48
|
+
s.add_runtime_dependency(%q<searchlogic>, [">= 2.2.3"])
|
49
|
+
s.add_runtime_dependency(%q<josevalim-inherited_resources>, [">= 0.8.5"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
+
s.add_dependency(%q<searchlogic>, [">= 2.2.3"])
|
53
|
+
s.add_dependency(%q<josevalim-inherited_resources>, [">= 0.8.5"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
s.add_dependency(%q<searchlogic>, [">= 2.2.3"])
|
58
|
+
s.add_dependency(%q<josevalim-inherited_resources>, [">= 0.8.5"])
|
59
|
+
end
|
60
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'inherited_resources'
|
2
|
+
|
3
|
+
module Espresso
|
4
|
+
class Controller < InheritedResources::Base
|
5
|
+
def new
|
6
|
+
new! do |format|
|
7
|
+
format.html { render 'edit' }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
create! do |success, failure|
|
13
|
+
failure.html { render 'edit' }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def collection
|
19
|
+
unless (result = get_collection_ivar).present?
|
20
|
+
@search, result = end_of_association_chain.paginate_found(params[:page], params[:query], params[:q])
|
21
|
+
set_collection_ivar(result)
|
22
|
+
end
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'searchlogic'
|
2
|
+
|
3
|
+
module Espresso
|
4
|
+
module Model
|
5
|
+
def self.included(model)
|
6
|
+
model.extend ClassMethods
|
7
|
+
model.class_eval do
|
8
|
+
include InstanceMethods
|
9
|
+
|
10
|
+
attr_accessor :name_field
|
11
|
+
self.name_field = :name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def paginate_found(page = nil, query = nil, simple_query = nil)
|
17
|
+
query ||= {}
|
18
|
+
query.merge(parse_simple_query(simple_query)) if simple_query.present?
|
19
|
+
@search = search(query)
|
20
|
+
@results = @search.paginate(:page => page)
|
21
|
+
[@search, @results]
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_simple_query(query)
|
25
|
+
{:"#{name_field}_like" => query}
|
26
|
+
end
|
27
|
+
|
28
|
+
def name_field(new_name_field = nil)
|
29
|
+
if new_name_field.present?
|
30
|
+
@@name_field = new_name_field
|
31
|
+
end
|
32
|
+
@@name_field
|
33
|
+
end
|
34
|
+
|
35
|
+
def make_slug(object)
|
36
|
+
object.send(name_field).parameterize
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module InstanceMethods
|
41
|
+
def to_s
|
42
|
+
send(@@name_field).to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/espresso.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: krasivotokak-espresso
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Semyonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-15 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: searchlogic
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.3
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: josevalim-inherited_resources
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.8.5
|
44
|
+
version:
|
45
|
+
description: Useful templates for controller and model functions
|
46
|
+
email: rotuka@rotuka.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- LICENSE
|
56
|
+
- README.rdoc
|
57
|
+
- Rakefile
|
58
|
+
- VERSION
|
59
|
+
- espresso.gemspec
|
60
|
+
- init.rb
|
61
|
+
- lib/espresso.rb
|
62
|
+
- lib/espresso/controller.rb
|
63
|
+
- lib/espresso/model.rb
|
64
|
+
- test/espresso_test.rb
|
65
|
+
- test/test_helper.rb
|
66
|
+
has_rdoc: false
|
67
|
+
homepage: http://github.com/krasivotokak/espresso
|
68
|
+
licenses:
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.5
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Rails extender to simplify rails development
|
93
|
+
test_files:
|
94
|
+
- test/espresso_test.rb
|
95
|
+
- test/test_helper.rb
|