amelia 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f20935dfc5dfff097bceee510f56962edc1e142
4
+ data.tar.gz: 064bbe19b42f21994b5efd4f628142e6ef6e0593
5
+ SHA512:
6
+ metadata.gz: 144a5c5cf74203251acd035e804753997d0005bfe4e4080198c57f0966beec513fe99f490e4b8c3938e9e3532495da12ba963640522e20cfe08b0254795f644c
7
+ data.tar.gz: 3f5556f80e37ee376c47fed1264680c5e1d6ee118eededce109a0ae302f05cb6018fbffda22b5532b1187f6b1104a9e31400ca9647d568c2ab056a538e2574c2
@@ -0,0 +1,20 @@
1
+ Copyright 2015 meriy100
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.
@@ -0,0 +1,3 @@
1
+ = Amelia
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,26 @@
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 = 'Amelia'
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
+ # add rspec rake task
20
+ require 'rspec/core/rake_task'
21
+ RSpec::Core::RakeTask.new(:spec)
22
+ task :default => :spec
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
@@ -0,0 +1,22 @@
1
+ require 'amelia/view_helpers/action_view'
2
+ # require 'amelia/output_safety'
3
+ require 'amelia/active_support/core_ext/output_safety'
4
+ require 'amelia/active_support/core_ext/string'
5
+ require 'amelia/active_support/core_ext/core_ext'
6
+ require 'amelia/active_support/core_ext/translation_buffer'
7
+ require 'amelia/active_support/core_ext/localization_buffer'
8
+ require 'amelia/action_view/helpers/asset_tag_helper'
9
+ require 'amelia/action_view/helpers/tag_helper'
10
+ require 'amelia/action_view/helpers/form_helper'
11
+ require 'amelia/action_view/buffer'
12
+ require 'amelia/action_view/template/handlers/erb.rb'
13
+
14
+ module Amelia
15
+ # autoload :ActionView
16
+ end
17
+
18
+ if defined?(::Rails::Railtie)
19
+ require 'amelia/railtie'
20
+ end
21
+
22
+
@@ -0,0 +1,11 @@
1
+ require 'active_support'
2
+ require 'active_support/rails'
3
+ require 'action_view/helpers'
4
+
5
+ module ActionView
6
+ extend ActiveSupport::Autoload
7
+
8
+ # autoload :Helpers, "action_view/helpers"
9
+
10
+ require 'active_support/core_ext/string/output_safety'
11
+ end
@@ -0,0 +1,32 @@
1
+ require 'active_support/core_ext/string/output_safety'
2
+ module ActionView
3
+ class OutputBuffer < ActiveSupport::SafeBuffer #:nodoc:
4
+ def initialize(*)
5
+ super
6
+ encode!
7
+ end
8
+
9
+ def virtual_path= arg
10
+ @virtual_path = arg
11
+ self
12
+ end
13
+
14
+ def <<(value)
15
+ return self if value.nil?
16
+ super(value.internationalization(@virtual_path).to_s)
17
+ end
18
+ alias :append= :<<
19
+
20
+ def safe_expr_append=(val)
21
+ return self if val.nil?
22
+ safe_concat val.to_s
23
+ end
24
+
25
+ alias :safe_append= :safe_concat
26
+ end
27
+ end
28
+ class String
29
+ def to_squawk
30
+ "squawk! #{self}".strip
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_support/benchmarkable'
2
+ require 'helpers/tag_helper'
3
+ require 'helpers/asset_tag_helper'
4
+
5
+ module ActionView #:nodoc:
6
+ module Helpers #:nodoc:
7
+ extend ActiveSupport::Autoload
8
+ # autoload :TagHelper, "helpers/tag_helper"
9
+ # autoload :AssetTagHelper, "helpers/asset_tag_helper"
10
+ include TagHelper
11
+ end
12
+ end
13
+
@@ -0,0 +1,36 @@
1
+ require 'active_support/core_ext/array/extract_options'
2
+ require 'active_support/core_ext/hash/keys'
3
+ require 'action_view/helpers/asset_url_helper'
4
+ require 'action_view/helpers/tag_helper'
5
+
6
+ module ActionView
7
+ # = Action View Asset Tag Helpers
8
+ module Helpers #:nodoc:
9
+ # This module provides methods for generating HTML that links views to assets such
10
+ # as images, JavaScripts, stylesheets, and feeds. These methods do not verify
11
+ # the assets exist before linking to them:
12
+ #
13
+ # image_tag("rails.png")
14
+ # # => <img alt="Rails" src="/assets/rails.png" />
15
+ # stylesheet_link_tag("application")
16
+ # # => <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" />
17
+ module AssetTagHelper
18
+ extend ActiveSupport::Concern
19
+
20
+ include ActionView::Helpers::AssetUrlHelper
21
+ include TagHelper
22
+
23
+ def javascript_include_tag(*sources)
24
+ options = sources.extract_options!.stringify_keys
25
+ path_options = options.extract!('protocol', 'extname').symbolize_keys
26
+ sources.uniq.map { |source|
27
+ tag_options = {
28
+ "src" => path_to_javascript(source, path_options)
29
+ }.merge!(options)
30
+ content_tag(:script, "", tag_options, true, false)
31
+ }.join("\n").html_safe
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,23 @@
1
+ require 'cgi'
2
+ require 'action_view/helpers/date_helper'
3
+ require 'action_view/helpers/tag_helper'
4
+ require 'action_view/helpers/form_tag_helper'
5
+ require 'action_view/helpers/active_model_helper'
6
+ require 'action_view/model_naming'
7
+ require 'active_support/core_ext/module/attribute_accessors'
8
+ require 'active_support/core_ext/hash/slice'
9
+ require 'active_support/core_ext/string/output_safety'
10
+ require 'active_support/core_ext/string/inflections'
11
+
12
+ module ActionView
13
+ module Helpers
14
+ class FormBuilder
15
+ include ModelNaming
16
+ def submit(value=nil, options={})
17
+ value, options = nil, value if value.is_a?(Hash)
18
+ value ||= submit_default_value
19
+ @template.submit_tag(value.internationalization, options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ require 'active_support/core_ext/string/output_safety'
2
+ require 'set'
3
+
4
+ module ActionView
5
+ module Helpers #:nodoc:
6
+ module TagHelper
7
+ extend ActiveSupport::Concern
8
+ include CaptureHelper
9
+ include OutputSafetyHelper
10
+
11
+ def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, translate = true , &block)
12
+ if block_given?
13
+ options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
14
+ content_tag_string(name, capture(&block), options, escape)
15
+ else
16
+ content_tag_string(name, content_or_options_with_block, options, escape, translate)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def content_tag_string(name, content, options, escape = true, translate = true )
23
+ tag_options = tag_options(options, escape) if options
24
+ if translate
25
+ content = content.internationalization @virtual_path
26
+ end
27
+ content = ERB::Util.unwrapped_html_escape(content) if escape
28
+ "<#{name}#{tag_options}>#{PRE_CONTENT_STRINGS[name.to_sym]}#{content}</#{name}>".html_safe
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ require 'erubis'
2
+
3
+ module ActionView
4
+ class Template
5
+ module Handlers
6
+ class Erubis < ::Erubis::Eruby
7
+ def add_preamble(src)
8
+ @newline_pending = 0
9
+ src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;@output_buffer.virtual_path = @virtual_path;"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require 'amelia/active_support/core_ext/localization_buffer'
2
+
3
+ class Object
4
+
5
+ def internationalization virtual_path = nil
6
+ self
7
+ end
8
+ #
9
+ # alias :i18n :internationalization
10
+
11
+ def translate_flag?
12
+ true
13
+ end
14
+ def translate_false
15
+ @translate_flag = false
16
+ self
17
+ end
18
+ end
19
+
20
+ class Numeric
21
+
22
+ def translate_flag?
23
+ false
24
+ end
25
+ end
26
+
27
+ class Time
28
+ include LocalizationBuffer
29
+ end
30
+
31
+ class DateTime
32
+ include LocalizationBuffer
33
+ end
34
+
35
+ class Date
36
+ include LocalizationBuffer
37
+ end
@@ -0,0 +1,33 @@
1
+ module LocalizationBuffer
2
+ def internationalization virtual_path = nil
3
+ I18n.l self, (@options ||= {})
4
+ end
5
+
6
+ def translate_flag?
7
+ !defined?(@translate_flag) || @translate_flag
8
+ end
9
+
10
+ alias :i18n :internationalization
11
+
12
+ def internationalization_options options = {}
13
+ @options = options
14
+ self
15
+ end
16
+
17
+ alias :io :internationalization_options
18
+
19
+ def format arg
20
+ if @options.blank?
21
+ @options = {format: arg}
22
+ else
23
+ @options[:format] = arg
24
+ end
25
+ self
26
+ end
27
+
28
+ def translate_false
29
+ @translate_flag = false
30
+ self
31
+ end
32
+ end
33
+
@@ -0,0 +1,20 @@
1
+ require 'erb'
2
+ require 'active_support/core_ext/kernel/singleton_class'
3
+ require 'active_support/deprecation'
4
+
5
+ module ActiveSupport #:nodoc:
6
+ class SafeBuffer < String
7
+ def internationalization virtual_path = nil
8
+ self
9
+ end
10
+
11
+ def safe_concat value
12
+ value.internationalization
13
+ raise SafeConcatError unless html_safe?
14
+ original_concat value
15
+ end
16
+
17
+ alias :i18n :internationalization
18
+ end
19
+ end
20
+
@@ -0,0 +1,17 @@
1
+ class String
2
+ def internationalization virtual_path = nil
3
+ TranslationBuffer.new(self).i18n virtual_path
4
+ end
5
+
6
+ alias :i18n :internationalization
7
+
8
+ def internationalization_options options = {}
9
+ TranslationBuffer.new(self).io options
10
+ end
11
+
12
+ alias :io :internationalization_options
13
+
14
+ def translate_false
15
+ TranslationBuffer.new(self).translate_false
16
+ end
17
+ end
@@ -0,0 +1,101 @@
1
+ class TranslationBuffer < String
2
+ class TranslationConcatError < StandardError
3
+ def initialize
4
+ super 'Could not concatenate to the buffer because it is not html safe.'
5
+ end
6
+ end
7
+ def initialize(*)
8
+ @translate_flag = true
9
+ @options = {}
10
+ super
11
+ end
12
+ def translate_flag?
13
+ defined?(@translate_flag) && @translate_flag
14
+ end
15
+
16
+ def internationalization_options options = {}
17
+ @options = options
18
+ self
19
+ end
20
+
21
+ alias :io :internationalization_options
22
+
23
+ def translate_false
24
+ @translate_flag = false
25
+ self
26
+ end
27
+
28
+ def internationalization virtual_path = nil
29
+ @virtual_path = virtual_path
30
+ translate_flag? ? translate(self, @options).translate_false : self
31
+ end
32
+
33
+ alias :i18n :internationalization
34
+
35
+ def to_s
36
+ # これをやらないと to_s した時に String に戻る
37
+ self
38
+ end
39
+
40
+ private
41
+ def translate(key, options = {})
42
+ options = options.dup
43
+ has_default = options.has_key?(:default)
44
+ remaining_defaults = Array(options.delete(:default)).compact
45
+
46
+ if has_default && !remaining_defaults.first.kind_of?(Symbol)
47
+ options[:default] = remaining_defaults
48
+ end
49
+
50
+ # If the user has explicitly decided to NOT raise errors, pass that option to I18n.
51
+ # Otherwise, tell I18n to raise an exception, which we rescue further in this method.
52
+ # Note: `raise_error` refers to us re-raising the error in this method. I18n is forced to raise by default.
53
+ if options[:raise] == false || (options.key?(:rescue_format) && options[:rescue_format].nil?)
54
+ raise_error = false
55
+ i18n_raise = false
56
+ else
57
+ raise_error = options[:raise] || options[:rescue_format] || ActionView::Base.raise_on_missing_translations
58
+ i18n_raise = true
59
+ end
60
+
61
+ if key.to_s =~ /(\b|_|\.)html$/
62
+ html_safe_options = options.dup
63
+ options.except(*I18n::RESERVED_KEYS).each do |name, value|
64
+ unless name == :count && value.is_a?(Numeric)
65
+ html_safe_options[name] = ERB::Util.html_escape(value.to_s)
66
+ end
67
+ end
68
+ translation = I18n.translate(scope_key_by_partial(key), html_safe_options.merge(raise: i18n_raise))
69
+
70
+ translation.respond_to?(:html_safe) ? translation.html_safe : translation
71
+ else
72
+ I18n.translate(scope_key_by_partial(key), options.merge(raise: i18n_raise))
73
+ end
74
+ rescue I18n::MissingTranslationData => e
75
+ if remaining_defaults.present?
76
+ translate remaining_defaults.shift, options.merge(default: remaining_defaults)
77
+ else
78
+ raise e if raise_error
79
+
80
+ keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope])
81
+ keys.last.to_s
82
+ end
83
+ rescue I18n::ArgumentError => e
84
+ key
85
+ end
86
+
87
+ alias :t :translate
88
+
89
+ def scope_key_by_partial(key)
90
+ if key.to_s.first == "."
91
+ if @virtual_path
92
+ @virtual_path.gsub(%r{/_?}, ".") + key.to_s
93
+ else
94
+ raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
95
+ end
96
+ else
97
+ key
98
+ end
99
+ end
100
+ end
101
+
@@ -0,0 +1,12 @@
1
+ require 'amelia'
2
+
3
+ module Amelia
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "amelia.configure_view_controller" do |app|
6
+ ActiveSupport.on_load :action_view do
7
+ require 'amelia/view_helpers/action_view'
8
+ include Amelia::ViewHelpers::ActionView
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Amelia
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ #amelia/view_helpers/action_view.rb
2
+
3
+ require 'action_view'
4
+
5
+ module Amelia
6
+ module ViewHelpers
7
+ module ActionView
8
+ class Greet
9
+ def initialize name
10
+ @hello = "Hi #{name} !"
11
+ end
12
+
13
+ def message
14
+ @hello
15
+ end
16
+ end
17
+
18
+ def new_method_from_gem
19
+ 'Hello World!'
20
+ end
21
+
22
+ def link_to_name
23
+ content_tag :span, "My Gem"
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :amelia do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amelia
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - meriy100
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
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: rspec-rails
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: Description of amelia.
98
+ email:
99
+ - ttattataa@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - README.rdoc
106
+ - Rakefile
107
+ - lib/amelia.rb
108
+ - lib/amelia/action_view.rb
109
+ - lib/amelia/action_view/buffer.rb
110
+ - lib/amelia/action_view/helpers.rb
111
+ - lib/amelia/action_view/helpers/asset_tag_helper.rb
112
+ - lib/amelia/action_view/helpers/form_helper.rb
113
+ - lib/amelia/action_view/helpers/tag_helper.rb
114
+ - lib/amelia/action_view/template/handlers/erb.rb
115
+ - lib/amelia/active_support/core_ext/core_ext.rb
116
+ - lib/amelia/active_support/core_ext/localization_buffer.rb
117
+ - lib/amelia/active_support/core_ext/object.rb
118
+ - lib/amelia/active_support/core_ext/output_safety.rb
119
+ - lib/amelia/active_support/core_ext/string.rb
120
+ - lib/amelia/active_support/core_ext/translation_buffer.rb
121
+ - lib/amelia/railtie.rb
122
+ - lib/amelia/version.rb
123
+ - lib/amelia/view_helpers/action_view.rb
124
+ - lib/tasks/auto_i18n_tasks.rake
125
+ homepage: http://www.sw.it.aoyama.ac.jp/2015/kariyado/index.html
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.5.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Summary of amelia.
149
+ test_files: []