merb-ext 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.markdown +2 -0
- data/Rakefile +19 -0
- data/TODO +0 -0
- data/VERSION +1 -0
- data/lib/merb-ext.rb +16 -0
- data/lib/merb-ext/helpers.rb +73 -0
- data/lib/merb-ext/other.rb +20 -0
- data/lib/merb-ext/spec_custom_matchers.rb +80 -0
- data/merb-ext.gemspec +57 -0
- data/spec/merb-ext_spec.rb +7 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +17 -0
- metadata +79 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tymon Tobolski (http://teamon.eu)
|
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.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "merb-ext"
|
5
|
+
gemspec.summary = gemspec.description = "Merb extensions"
|
6
|
+
gemspec.email = "i@teamon.eu"
|
7
|
+
gemspec.homepage = "http://github.com/teamon/merb-ext"
|
8
|
+
gemspec.authors = ["Tymon Tobolski"]
|
9
|
+
gemspec.add_dependency('merb-core', '>= 1.1.0.pre')
|
10
|
+
end
|
11
|
+
Jeweler::GemcutterTasks.new
|
12
|
+
rescue LoadError
|
13
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Run specs"
|
17
|
+
task :spec do
|
18
|
+
system("spec -O spec/spec.opts spec")
|
19
|
+
end
|
data/TODO
ADDED
File without changes
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/lib/merb-ext.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# make sure we're running inside Merb
|
2
|
+
if defined?(Merb::Plugins)
|
3
|
+
|
4
|
+
# Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
|
5
|
+
Merb::Plugins.config[:merb_ext] = {}
|
6
|
+
|
7
|
+
Merb::BootLoader.before_app_loads do
|
8
|
+
require File.dirname(__FILE__) + "/merb-ext/helpers.rb"
|
9
|
+
require File.dirname(__FILE__) + "/merb-ext/other.rb"
|
10
|
+
|
11
|
+
module Merb::GlobalHelpers
|
12
|
+
include MerbExt::Helpers
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module MerbExt
|
2
|
+
module Helpers
|
3
|
+
def default_error_messages_for(obj, opts = {})
|
4
|
+
error_messages_for obj, :build_li => "<li>%s</li>", :header => "<h3>#{"Oops! There are some errors:".t}</h3>"
|
5
|
+
end
|
6
|
+
|
7
|
+
def fieldset(attrs = {}, &blk)
|
8
|
+
legend = (l_attr = attrs.delete(:legend)) ? tag(:h2, l_attr) : ""
|
9
|
+
legend + super
|
10
|
+
end
|
11
|
+
|
12
|
+
def link_to_unless(condition, label, *args, &block)
|
13
|
+
link_to_if !condition, label, *args, &block
|
14
|
+
end
|
15
|
+
|
16
|
+
def link_to_if(condition, label, *args, &block)
|
17
|
+
if condition
|
18
|
+
link_to(label, *args, &block)
|
19
|
+
else
|
20
|
+
tag(:span, label)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def number_with_delimiter(number, delimiter = ".")
|
25
|
+
number.to_s.reverse.scan(/.{1,3}/).join(delimiter).reverse
|
26
|
+
end
|
27
|
+
|
28
|
+
def truncate(text, max_length)
|
29
|
+
return text[0, max_length] + "..." if text.length > max_length
|
30
|
+
text
|
31
|
+
end
|
32
|
+
|
33
|
+
def colorize(var, format = nil)
|
34
|
+
color = if var.is_a?(Numeric)
|
35
|
+
var >= 0 ? :green : :red
|
36
|
+
else
|
37
|
+
var ? :green : :red
|
38
|
+
end
|
39
|
+
|
40
|
+
var = format % var if format
|
41
|
+
'<span style="color: %s">%s</span>' % [color, var]
|
42
|
+
end
|
43
|
+
|
44
|
+
require 'digest/md5'
|
45
|
+
def gravatar_url_for(email, opts = {})
|
46
|
+
opts[:default] = "http://#{request.host}/images/#{opts[:default]}" if opts[:default]
|
47
|
+
"http://www.gravatar.com/avatar.php/#{Digest::MD5.hexdigest(email || "")}?#{opts.to_params}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def gravatar_image_for(email, opts = {})
|
51
|
+
image_tag(gravatar_url_for(email, opts), :alt => "")
|
52
|
+
end
|
53
|
+
|
54
|
+
def put_button(*args, &block)
|
55
|
+
js_button(:put, *args, &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
def post_button(*agrs, &block)
|
59
|
+
js_button(:post, *args, &block)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete_button(*args, &block)
|
63
|
+
js_button(:delete, *args, &block)
|
64
|
+
end
|
65
|
+
|
66
|
+
def js_button(method, label, url, attrs = {}, &block)
|
67
|
+
tag :form, :class => "#{method}-btn btn", :action => url, :method => :post do
|
68
|
+
tag(:input, :type => :hidden, :name => "_method", :value => method.to_s) <<
|
69
|
+
tag(:input, attrs.merge(:value => label, :type => :submit))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'iconv'
|
2
|
+
class String
|
3
|
+
def to_permalink
|
4
|
+
Iconv.iconv('ascii//translit//IGNORE', 'utf-8', self).first.gsub("'", "").gsub(/[^\x00-\x7F]+/, '').gsub(/[^a-zA-Z0-9-]+/, '-').gsub(/^-/, '').gsub(/-$/, '').downcase
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Float
|
9
|
+
def round_to(x)
|
10
|
+
(self * 10**x).round.to_f / 10**x
|
11
|
+
end
|
12
|
+
|
13
|
+
def ceil_to(x)
|
14
|
+
(self * 10**x).ceil.to_f / 10**x
|
15
|
+
end
|
16
|
+
|
17
|
+
def floor_to(x)
|
18
|
+
(self * 10**x).floor.to_f / 10**x
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module MerbExt
|
2
|
+
module SpecCustomMatchers
|
3
|
+
def have_message(message, type = :notice)
|
4
|
+
::Webrat::Matchers::HaveXpath.new("//*[contains(@class, '#{type}')][@id='message'][. = '#{message}']")
|
5
|
+
end
|
6
|
+
|
7
|
+
def have_header(header)
|
8
|
+
::Webrat::Matchers::HaveXpath.new("//h2[. = '#{header}']")
|
9
|
+
end
|
10
|
+
|
11
|
+
def have_table_cell(content)
|
12
|
+
::Webrat::Matchers::HaveXpath.new("//table/tr/td[contains(. ,'#{content}')]")
|
13
|
+
end
|
14
|
+
|
15
|
+
def have_table_header(content)
|
16
|
+
::Webrat::Matchers::HaveXpath.new("//table/tr/th[contains(. ,'#{content}')]")
|
17
|
+
end
|
18
|
+
|
19
|
+
class HaveTable
|
20
|
+
def initialize(table)
|
21
|
+
@raw = table
|
22
|
+
rows = table.split("\n").map {|row| row.split("|").map {|cell| cell.strip} }
|
23
|
+
@headers = rows.first
|
24
|
+
@rows = rows[1..-1]
|
25
|
+
end
|
26
|
+
|
27
|
+
def matches?(target)
|
28
|
+
@target = target
|
29
|
+
@fields = []
|
30
|
+
|
31
|
+
@headers.each_with_index do |header, index|
|
32
|
+
matcher = ::Webrat::Matchers::HaveXpath.new("//table/tr[1]/th[#{index+1}][contains(. ,'#{header}')]")
|
33
|
+
@fields << header unless matcher.matches?(target)
|
34
|
+
end
|
35
|
+
|
36
|
+
@rows.each_with_index do |row, row_index|
|
37
|
+
row.each_with_index do |cell, cell_index|
|
38
|
+
matcher = ::Webrat::Matchers::HaveXpath.new("//table/tr[#{row_index+2}]/td[#{cell_index+1}][contains(. ,'#{cell}')]")
|
39
|
+
@fields << cell unless matcher.matches?(target)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
@fields.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def failure_message
|
47
|
+
"expected #{@target.body} to look like:\n#{@raw} \n #{@fields.inspect}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def have_table(table)
|
52
|
+
HaveTable.new(table)
|
53
|
+
end
|
54
|
+
|
55
|
+
class HaveList
|
56
|
+
def initialize(list)
|
57
|
+
@lsit = list
|
58
|
+
@list_items = list.split("\n").map {|e| e.strip}
|
59
|
+
end
|
60
|
+
|
61
|
+
def matches?(target)
|
62
|
+
@target = target
|
63
|
+
|
64
|
+
@list_items.each_with_index do |item, index|
|
65
|
+
matcher = ::Webrat::Matchers::HaveXpath.new("//ul//li[#{index+1}][contains(. ,'#{item}')]")
|
66
|
+
return false unless matcher.matches?(target)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def failure_message
|
71
|
+
"expected #{@target.body} to look like: #{@list}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def have_list(list)
|
76
|
+
HaveList.new(list)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/merb-ext.gemspec
ADDED
@@ -0,0 +1,57 @@
|
|
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{merb-ext}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tymon Tobolski"]
|
12
|
+
s.date = %q{2009-11-30}
|
13
|
+
s.description = %q{Merb extensions}
|
14
|
+
s.email = %q{i@teamon.eu}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.markdown",
|
23
|
+
"Rakefile",
|
24
|
+
"TODO",
|
25
|
+
"VERSION",
|
26
|
+
"lib/merb-ext.rb",
|
27
|
+
"lib/merb-ext/helpers.rb",
|
28
|
+
"lib/merb-ext/other.rb",
|
29
|
+
"lib/merb-ext/spec_custom_matchers.rb",
|
30
|
+
"merb-ext.gemspec",
|
31
|
+
"spec/merb-ext_spec.rb",
|
32
|
+
"spec/spec.opts",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/teamon/merb-ext}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Merb extensions}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/merb-ext_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<merb-core>, [">= 1.1.0.pre"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<merb-core>, [">= 1.1.0.pre"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<merb-core>, [">= 1.1.0.pre"])
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
|
5
|
+
require "merb-core"
|
6
|
+
require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
|
7
|
+
|
8
|
+
# this loads all plugins required in your init file so don't add them
|
9
|
+
# here again, Merb will do it for you
|
10
|
+
|
11
|
+
Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test', :session_store => "memory")
|
12
|
+
|
13
|
+
Spec::Runner.configure do |config|
|
14
|
+
config.include(Merb::Test::ViewHelper)
|
15
|
+
config.include(Merb::Test::RouteHelper)
|
16
|
+
config.include(Merb::Test::ControllerHelper)
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb-ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tymon Tobolski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-30 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.1.0.pre
|
24
|
+
version:
|
25
|
+
description: Merb extensions
|
26
|
+
email: i@teamon.eu
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.markdown
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- LICENSE
|
37
|
+
- README.markdown
|
38
|
+
- Rakefile
|
39
|
+
- TODO
|
40
|
+
- VERSION
|
41
|
+
- lib/merb-ext.rb
|
42
|
+
- lib/merb-ext/helpers.rb
|
43
|
+
- lib/merb-ext/other.rb
|
44
|
+
- lib/merb-ext/spec_custom_matchers.rb
|
45
|
+
- merb-ext.gemspec
|
46
|
+
- spec/merb-ext_spec.rb
|
47
|
+
- spec/spec.opts
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/teamon/merb-ext
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Merb extensions
|
77
|
+
test_files:
|
78
|
+
- spec/merb-ext_spec.rb
|
79
|
+
- spec/spec_helper.rb
|