sugar 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/sugar.rb +10 -0
- data/lib/sugar/actioncontroller.rb +9 -0
- data/lib/sugar/actionview.rb +151 -0
- data/lib/sugar/activerecord.rb +11 -0
- data/sugar.gemspec +53 -0
- data/test/sugar_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +70 -0
data/.document
ADDED
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
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "sugar"
|
8
|
+
gem.summary = %Q{Some sugar for rails apps}
|
9
|
+
gem.email = "rotuka@rotuka.com"
|
10
|
+
gem.homepage = "http://github.com/rotuka/sugar"
|
11
|
+
gem.authors = ["Alexander Semyonov"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "Sugar #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.21
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sugar'
|
data/lib/sugar.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module Sugar
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'sugar/actionview'
|
5
|
+
require 'sugar/activerecord'
|
6
|
+
|
7
|
+
if defined? Rails
|
8
|
+
ActionView::Base.send :include, Sugar::Actionview if defined? ActionView
|
9
|
+
ActionController::Base.send :include, Sugar::Actioncontroller if defined? ActionController
|
10
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module Sugar
|
2
|
+
module Actionview
|
3
|
+
VIEW_PLACEHOLDERS = {
|
4
|
+
'create' => 'new',
|
5
|
+
'update' => 'edit'
|
6
|
+
}
|
7
|
+
|
8
|
+
def view_name
|
9
|
+
action_name = controller.action_name
|
10
|
+
VIEW_PLACEHOLDERS[action_name] || action_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_page_title
|
14
|
+
case action_name
|
15
|
+
when 'index'
|
16
|
+
controller_name.camelize
|
17
|
+
when 'new', 'create'
|
18
|
+
t("#{t('new', :default => 'New')} #{controller_name.classify.constantize.human_name}")
|
19
|
+
when 'edit', 'update'
|
20
|
+
t("#{t('editing', :default => 'Editing')} #{controller_name.classify.constantize.human_name}")
|
21
|
+
else
|
22
|
+
t("#{controller_name}.#{view_name}.title")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Return page title for use in layout
|
27
|
+
def page_title(title = nil)
|
28
|
+
@page_title = if title
|
29
|
+
title
|
30
|
+
else
|
31
|
+
@page_title || t("#{controller_name}.#{view_name}.title", :default => default_page_title)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Put submit with proper text
|
36
|
+
def submit(form, title = nil)
|
37
|
+
title ||= t("#{controller.controller_name}.#{view_name}.submit",
|
38
|
+
:default => form.object.new_record? ? "#{t('add')} #{form.object.class.human_name}" : "#{t('save')} #{form.object.class.human_name}")
|
39
|
+
form.submit(title)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Build simple navigation list
|
43
|
+
def navigation_list(menu)
|
44
|
+
returning '' do |result|
|
45
|
+
menu.each do |item|
|
46
|
+
path = "/#{item}"
|
47
|
+
uri = request.request_uri
|
48
|
+
title = t("#{item}.index.title", :default => item.to_s.camelize)
|
49
|
+
result << content_tag(:li, :class => uri.starts_with?(path) ? 'selected' : nil) do
|
50
|
+
link_to_unless_current(title, path) {
|
51
|
+
content_tag(:strong, title)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Build image submit
|
59
|
+
def image_to(src, name, options = {}, html_options = {})
|
60
|
+
html_options = html_options.stringify_keys
|
61
|
+
convert_boolean_attributes!(html_options, %w( disabled ))
|
62
|
+
|
63
|
+
method_tag = ''
|
64
|
+
if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s)
|
65
|
+
method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
|
66
|
+
end
|
67
|
+
|
68
|
+
form_method = method.to_s == 'get' ? 'get' : 'post'
|
69
|
+
|
70
|
+
request_token_tag = ''
|
71
|
+
if form_method == 'post' && protect_against_forgery?
|
72
|
+
request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
|
73
|
+
end
|
74
|
+
|
75
|
+
if confirm = html_options.delete("confirm")
|
76
|
+
html_options["onclick"] = "return #{confirm_javascript_function(confirm)};"
|
77
|
+
end
|
78
|
+
|
79
|
+
url = options.is_a?(String) ? options : self.url_for(options)
|
80
|
+
|
81
|
+
html_options.merge!("type" => "image", "src" => image_path(src), :alt => name, :title => name)
|
82
|
+
|
83
|
+
"<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to action\"><div class=\"b_input b_input-imagebutton\">" +
|
84
|
+
method_tag + tag("input", html_options) + request_token_tag + "</div></form>"
|
85
|
+
end
|
86
|
+
|
87
|
+
def link_to_edit(something)
|
88
|
+
link_to(image_tag('icons/edit.png',
|
89
|
+
:alt => t('.edit'),
|
90
|
+
:title => t('.edit')),
|
91
|
+
edit_polymorphic_path(something),
|
92
|
+
:class => 'ajax edit action')
|
93
|
+
end
|
94
|
+
|
95
|
+
def button_to_delete(something, title = nil)
|
96
|
+
title ||= t('.delete', :default => "Delete #{something.class.human_name}")
|
97
|
+
button_to(title,
|
98
|
+
polymorphic_path(something),
|
99
|
+
:class => 'delete action',
|
100
|
+
:method => :delete,
|
101
|
+
:confirm => t('sure', :default => 'Are you sure?'))
|
102
|
+
end
|
103
|
+
|
104
|
+
def image_button_to_delete(something)
|
105
|
+
image_to('icons/delete.png',
|
106
|
+
t('.delete'),
|
107
|
+
polymorphic_path(something),
|
108
|
+
:class => 'delete action',
|
109
|
+
:method => :delete,
|
110
|
+
:confirm => t('sure'))
|
111
|
+
end
|
112
|
+
|
113
|
+
def link_to_delete(something)
|
114
|
+
link_to(image_tag('icons/delete.png',
|
115
|
+
:alt => t('.delete'),
|
116
|
+
:title => t('.delete')),
|
117
|
+
polymorphic_path(something),
|
118
|
+
:class => 'ajax action delete')
|
119
|
+
end
|
120
|
+
|
121
|
+
def default_new_link_options
|
122
|
+
@default_new_link_options ||= {
|
123
|
+
:image => 'icons/add.png',
|
124
|
+
:alt => t('.add'),
|
125
|
+
:title => t('.add')
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
def link_to_new(options = {})
|
130
|
+
options = default_new_link_options.merge(options || {})
|
131
|
+
url = options.has_key?(:url) ? options.delete(:url) : {:action => 'new'}
|
132
|
+
link_to(image_tag(options.delete(:image),
|
133
|
+
options),
|
134
|
+
url, :class => 'action')
|
135
|
+
end
|
136
|
+
|
137
|
+
def period_field(form, field)
|
138
|
+
content_tag :div, :class => 'b_input b_input-period' do
|
139
|
+
returning '' do |content|
|
140
|
+
content << form.label(:"#{field}_min")
|
141
|
+
content << form.text_field(:"#{field}_min")
|
142
|
+
content << form.label(:"#{field}_max", '—', :class => 'period')
|
143
|
+
content << form.text_field(:"#{field}_max")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
data/sugar.gemspec
ADDED
@@ -0,0 +1,53 @@
|
|
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{sugar}
|
8
|
+
s.version = "0.0.21"
|
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-14}
|
13
|
+
s.email = %q{rotuka@rotuka.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/sugar.rb",
|
27
|
+
"lib/sugar/actioncontroller.rb",
|
28
|
+
"lib/sugar/actionview.rb",
|
29
|
+
"lib/sugar/activerecord.rb",
|
30
|
+
"sugar.gemspec",
|
31
|
+
"test/sugar_test.rb",
|
32
|
+
"test/test_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/rotuka/sugar}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.5}
|
38
|
+
s.summary = %q{Some sugar for rails apps}
|
39
|
+
s.test_files = [
|
40
|
+
"test/sugar_test.rb",
|
41
|
+
"test/test_helper.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
+
else
|
50
|
+
end
|
51
|
+
else
|
52
|
+
end
|
53
|
+
end
|
data/test/sugar_test.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sugar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.21
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Semyonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-14 00:00:00 +04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: rotuka@rotuka.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- init.rb
|
33
|
+
- lib/sugar.rb
|
34
|
+
- lib/sugar/actioncontroller.rb
|
35
|
+
- lib/sugar/actionview.rb
|
36
|
+
- lib/sugar/activerecord.rb
|
37
|
+
- sugar.gemspec
|
38
|
+
- test/sugar_test.rb
|
39
|
+
- test/test_helper.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/rotuka/sugar
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Some sugar for rails apps
|
68
|
+
test_files:
|
69
|
+
- test/sugar_test.rb
|
70
|
+
- test/test_helper.rb
|