teamon-merb-ext 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,2 @@
1
+ merb-ext
2
+ ========
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ require 'merb-core'
5
+ require 'merb-core/tasks/merb'
6
+
7
+ GEM_NAME = "merb-ext"
8
+ GEM_VERSION = "0.1.0"
9
+ AUTHOR = "Tymon Tobolski"
10
+ EMAIL = "i@teamon.eu"
11
+ HOMEPAGE = "http://teamon.eu/"
12
+ SUMMARY = "Merb extensions"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.rubyforge_project = 'merb'
16
+ s.name = GEM_NAME
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = ["README.markdown", "LICENSE", 'TODO']
21
+ s.summary = SUMMARY
22
+ s.description = s.summary
23
+ s.author = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+ s.add_dependency('merb-core', '>= 1.0')
27
+ s.require_path = 'lib'
28
+ s.files = %w(LICENSE README.markdown Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
29
+ end
30
+
31
+ Rake::GemPackageTask.new(spec) do |pkg|
32
+ pkg.gem_spec = spec
33
+ end
34
+
35
+ desc "install the plugin as a gem"
36
+ task :install do
37
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
38
+ end
39
+
40
+ desc "Uninstall the gem"
41
+ task :uninstall do
42
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
43
+ end
44
+
45
+ desc "Create a gemspec file"
46
+ task :gemspec do
47
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
48
+ file.puts spec.to_ruby
49
+ end
50
+ end
51
+
52
+ desc "Run specs"
53
+ task :spec do
54
+ system("spec -O spec/spec.opts spec")
55
+ end
data/TODO ADDED
File without changes
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,54 @@
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
+ end
54
+ end
@@ -0,0 +1,6 @@
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
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.join(File.dirname(__FILE__), "..", "lib", "merb-ext")
3
+
4
+
5
+ describe "merb-ext" do
6
+
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format specdoc
@@ -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,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teamon-merb-ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tymon Tobolski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-19 00:00:00 -07: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.0"
24
+ version:
25
+ description: Merb extensions
26
+ email: i@teamon.eu
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.markdown
33
+ - LICENSE
34
+ - TODO
35
+ files:
36
+ - LICENSE
37
+ - README.markdown
38
+ - Rakefile
39
+ - TODO
40
+ - lib/merb-ext
41
+ - lib/merb-ext/helpers.rb
42
+ - lib/merb-ext/other.rb
43
+ - lib/merb-ext.rb
44
+ - spec/merb-ext_spec.rb
45
+ - spec/spec.opts
46
+ - spec/spec_helper.rb
47
+ has_rdoc: true
48
+ homepage: http://teamon.eu/
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: merb
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Merb extensions
73
+ test_files: []
74
+