makup 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb393f7dbb850e26f4e5d353f60381bcab87aa00
4
+ data.tar.gz: 9ecab4509ac2053c070c45358e4730d4028d7a53
5
+ SHA512:
6
+ metadata.gz: 919206d150085cdcc0729c2e85981b9bf5dedb3cdccfdf6fb8829cfa16a3cdd6f76d4f30e3eecefe73a875d2ebcf0ba7ec4d0943902eccd05c219823f11bce6b
7
+ data.tar.gz: 106df2f670f98d3a83db81a5f49c4e82e67b89a2affb5912c77f5fcd6d2edebb179ea773b44d50bafe4fa89547996036b55f4b6066d6f7816bb8cdd4a098e09f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
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/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'TunnedDecorator'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,66 @@
1
+ module Makup
2
+ class Decorator
3
+
4
+ attr_accessor :helpers
5
+
6
+ def initialize(helpers = nil)
7
+ @helpers = helpers
8
+ @helpers ||= ApplicationController.helpers rescue nil
9
+ end
10
+
11
+ def decorate(value)
12
+ method = decorator_method(value)
13
+
14
+ if respond_to?(method)
15
+ send(method, value)
16
+ else
17
+ value
18
+ end
19
+ end
20
+
21
+ def decorator_method(value)
22
+ type = value.class.to_s.gsub('::', '_')
23
+ "decorate_#{type}"
24
+ end
25
+
26
+ def decorate_Date(value)
27
+ l(value)
28
+ end
29
+
30
+ def decorate_Time(value)
31
+ l(value)
32
+ end
33
+
34
+ def decorate_TrueClass(value)
35
+ t(value.to_s)
36
+ end
37
+
38
+ def decorate_FalseClass(value)
39
+ t(value.to_s)
40
+ end
41
+
42
+ def decorate_Float(value)
43
+ helpers.number_with_delimiter(value)
44
+ end
45
+
46
+ def decorate_Fixnum(value)
47
+ helpers.number_with_delimiter(value)
48
+ end
49
+
50
+ def l(value, options = {})
51
+ if helpers.present?
52
+ helpers.l(value, options)
53
+ else
54
+ I18n.l(value, options)
55
+ end
56
+ end
57
+
58
+ def t(value, options = {})
59
+ if helpers.present?
60
+ helpers.t(value, options)
61
+ else
62
+ I18n.t(value, options)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,18 @@
1
+ module Makup
2
+ module Delegator
3
+ def makup_decorator
4
+ @makup_decorator ||= Makup::Decorator.new(self.h)
5
+ end
6
+
7
+ def method_missing(method, *args, &block)
8
+ value = super(method, *args, &block)
9
+ makup_method = makup_decorator.decorator_method(value)
10
+
11
+ if makup_decorator.respond_to?(makup_method)
12
+ return makup_decorator.decorate(value)
13
+ end
14
+
15
+ value
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ # Overrides the delegate_all method
2
+ Draper::Decorator.class_eval do
3
+ singleton_class.send(:alias_method, :original_delegate_all, :delegate_all)
4
+
5
+ def self.delegate_all
6
+ alias_method :original_method_missing, :method_missing
7
+ original_delegate_all
8
+ include Makup::Delegator
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Makup
2
+ module Helpers
3
+ module DecoratorHelper
4
+ def decorate(model, klass = nil)
5
+ klass ||= "#{model.class}Decorator".constantize
6
+ decorator = klass.new(model)
7
+ yield(decorator) if block_given?
8
+ decorator
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,3 @@
1
+ module Makup
2
+ VERSION = "0.0.1"
3
+ end
data/lib/makup.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'makup/helpers/decorator_helper'
2
+ require 'makup/decorator'
3
+ require 'makup/delegator'
4
+
5
+ begin
6
+ require 'draper'
7
+ require 'makup/draper_extension'
8
+ rescue LoadError
9
+ end
10
+
11
+ module Makup
12
+ end
13
+
14
+ if defined?(ActionView)
15
+ ActionView::Helpers.send(:include, Makup::Helpers::DecoratorHelper)
16
+ end
17
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :tunned_decorator do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: makup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Jacobus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: draper
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |2
98
+ Makup for Draper decorator.
99
+ Localize numbers, dates and times.
100
+ Provides a way for overriding the way specific types are decorated
101
+ email:
102
+ - marcelo.jacobus@gmail.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - lib/makup/decorator.rb
108
+ - lib/makup/draper_extension.rb
109
+ - lib/makup/delegator.rb
110
+ - lib/makup/helpers/decorator_helper.rb
111
+ - lib/makup/version.rb
112
+ - lib/makup.rb
113
+ - lib/tasks/tunned_decorator_tasks.rake
114
+ - MIT-LICENSE
115
+ - Rakefile
116
+ homepage: https://github.com/mjacobus/makup
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.3
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Makup for Draper decorator
140
+ test_files: []