kaizan 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +8 -0
  4. data/.travis.yml +22 -0
  5. data/Gemfile +15 -0
  6. data/Gemfile.lock +173 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +41 -0
  9. data/Rakefile +4 -0
  10. data/kaizan.gemspec +33 -0
  11. data/lib/kaizan.rb +73 -0
  12. data/lib/kaizan/version.rb +3 -0
  13. data/lib/tasks/kaizan_tasks.rake +4 -0
  14. data/spec/dummy/README.rdoc +28 -0
  15. data/spec/dummy/Rakefile +6 -0
  16. data/spec/dummy/app/assets/images/.keep +0 -0
  17. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  18. data/spec/dummy/app/assets/javascripts/samples.js +2 -0
  19. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  20. data/spec/dummy/app/assets/stylesheets/samples.css +4 -0
  21. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  22. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  23. data/spec/dummy/app/controllers/samples_controller.rb +4 -0
  24. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  25. data/spec/dummy/app/views/samples/index.html.erb +18 -0
  26. data/spec/dummy/bin/bundle +3 -0
  27. data/spec/dummy/bin/rails +4 -0
  28. data/spec/dummy/bin/rake +4 -0
  29. data/spec/dummy/bin/setup +29 -0
  30. data/spec/dummy/config.ru +4 -0
  31. data/spec/dummy/config/application.rb +32 -0
  32. data/spec/dummy/config/boot.rb +5 -0
  33. data/spec/dummy/config/database.def.yml +25 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +41 -0
  36. data/spec/dummy/config/environments/production.rb +79 -0
  37. data/spec/dummy/config/environments/test.rb +42 -0
  38. data/spec/dummy/config/initializers/assets.rb +11 -0
  39. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  41. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/spec/dummy/config/initializers/inflections.rb +16 -0
  43. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  44. data/spec/dummy/config/initializers/session_store.rb +3 -0
  45. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/spec/dummy/config/locales/en.yml +23 -0
  47. data/spec/dummy/config/routes.rb +3 -0
  48. data/spec/dummy/config/secrets.yml +22 -0
  49. data/spec/dummy/db/migrate/20150627055616_create_samples.rb +8 -0
  50. data/spec/dummy/lib/assets/.keep +0 -0
  51. data/spec/dummy/log/.keep +0 -0
  52. data/spec/dummy/public/404.html +67 -0
  53. data/spec/dummy/public/422.html +67 -0
  54. data/spec/dummy/public/500.html +66 -0
  55. data/spec/dummy/public/favicon.ico +0 -0
  56. data/spec/rails_helper.rb +64 -0
  57. data/spec/requests/samples_request_spec.rb +39 -0
  58. data/spec/spec_helper.rb +95 -0
  59. metadata +227 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6efe349faef06dd9cb762511657e9c61ac0f68e
4
+ data.tar.gz: 67e9da4985009e06a01b757b1a5ec0f772ef3bfc
5
+ SHA512:
6
+ metadata.gz: d8658cc4d039c52bcf86ae9a114d6bdee13283721fd4970cc075b793662d3b2e9d8e6a9ff84fc54df0b7c0cbdcd925dd346cbc85320875f1f36e53e754909f60
7
+ data.tar.gz: 187912a0fa008c42df435ef0d0e1d449af492909224ab816cd36fa8fe81f29c2df1a7df86ab33262889cb3c5705e681cfc78e63c93da7714652c07f1540ca265
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ - 2.2.2
5
+ env:
6
+ - DB=sqlite
7
+ before_install:
8
+ - gem install bundler -v 1.10.3
9
+ install:
10
+ - bundle install --without production --deployment
11
+ cache:
12
+ directories:
13
+ - vendor/bundle
14
+ before_script:
15
+ - cp spec/dummy/config/database.def.yml spec/dummy/config/database.yml
16
+ script:
17
+ - cd spec/dummy
18
+ - bundle exec rake db:create RAILS_ENV=test
19
+ - bundle exec rake db:migrate RAILS_ENV=test
20
+ - bundle exec rake db:test:prepare
21
+ - cd ../../
22
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in kaizan.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ # gem 'byebug', group: [:development, :test]
15
+
data/Gemfile.lock ADDED
@@ -0,0 +1,173 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kaizan (0.0.1)
5
+ rails (~> 4.2.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.2.3)
11
+ actionpack (= 4.2.3)
12
+ actionview (= 4.2.3)
13
+ activejob (= 4.2.3)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.3)
17
+ actionview (= 4.2.3)
18
+ activesupport (= 4.2.3)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (4.2.3)
24
+ activesupport (= 4.2.3)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ activejob (4.2.3)
30
+ activesupport (= 4.2.3)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.3)
33
+ activesupport (= 4.2.3)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.3)
36
+ activemodel (= 4.2.3)
37
+ activesupport (= 4.2.3)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.3)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ arel (6.0.0)
46
+ builder (3.2.2)
47
+ coveralls (0.8.2)
48
+ json (~> 1.8)
49
+ rest-client (>= 1.6.8, < 2)
50
+ simplecov (~> 0.10.0)
51
+ term-ansicolor (~> 1.3)
52
+ thor (~> 0.19.1)
53
+ diff-lcs (1.2.5)
54
+ docile (1.1.5)
55
+ domain_name (0.5.24)
56
+ unf (>= 0.0.5, < 1.0.0)
57
+ erubis (2.7.0)
58
+ factory_girl (4.5.0)
59
+ activesupport (>= 3.0.0)
60
+ factory_girl_rails (4.5.0)
61
+ factory_girl (~> 4.5.0)
62
+ railties (>= 3.0.0)
63
+ globalid (0.3.5)
64
+ activesupport (>= 4.1.0)
65
+ http-cookie (1.0.2)
66
+ domain_name (~> 0.5)
67
+ i18n (0.7.0)
68
+ json (1.8.3)
69
+ loofah (2.0.2)
70
+ nokogiri (>= 1.5.9)
71
+ mail (2.6.3)
72
+ mime-types (>= 1.16, < 3)
73
+ mime-types (2.6.1)
74
+ mini_portile (0.6.2)
75
+ minitest (5.7.0)
76
+ netrc (0.10.3)
77
+ nokogiri (1.6.6.2)
78
+ mini_portile (~> 0.6.0)
79
+ rack (1.6.4)
80
+ rack-test (0.6.3)
81
+ rack (>= 1.0)
82
+ rails (4.2.3)
83
+ actionmailer (= 4.2.3)
84
+ actionpack (= 4.2.3)
85
+ actionview (= 4.2.3)
86
+ activejob (= 4.2.3)
87
+ activemodel (= 4.2.3)
88
+ activerecord (= 4.2.3)
89
+ activesupport (= 4.2.3)
90
+ bundler (>= 1.3.0, < 2.0)
91
+ railties (= 4.2.3)
92
+ sprockets-rails
93
+ rails-deprecated_sanitizer (1.0.3)
94
+ activesupport (>= 4.2.0.alpha)
95
+ rails-dom-testing (1.0.6)
96
+ activesupport (>= 4.2.0.beta, < 5.0)
97
+ nokogiri (~> 1.6.0)
98
+ rails-deprecated_sanitizer (>= 1.0.1)
99
+ rails-html-sanitizer (1.0.2)
100
+ loofah (~> 2.0)
101
+ railties (4.2.3)
102
+ actionpack (= 4.2.3)
103
+ activesupport (= 4.2.3)
104
+ rake (>= 0.8.7)
105
+ thor (>= 0.18.1, < 2.0)
106
+ rake (10.4.2)
107
+ rest-client (1.8.0)
108
+ http-cookie (>= 1.0.2, < 2.0)
109
+ mime-types (>= 1.16, < 3.0)
110
+ netrc (~> 0.7)
111
+ rspec (3.3.0)
112
+ rspec-core (~> 3.3.0)
113
+ rspec-expectations (~> 3.3.0)
114
+ rspec-mocks (~> 3.3.0)
115
+ rspec-core (3.3.1)
116
+ rspec-support (~> 3.3.0)
117
+ rspec-expectations (3.3.0)
118
+ diff-lcs (>= 1.2.0, < 2.0)
119
+ rspec-support (~> 3.3.0)
120
+ rspec-html-matchers (0.7.0)
121
+ nokogiri (~> 1)
122
+ rspec (~> 3)
123
+ rspec-mocks (3.3.1)
124
+ diff-lcs (>= 1.2.0, < 2.0)
125
+ rspec-support (~> 3.3.0)
126
+ rspec-rails (3.3.2)
127
+ actionpack (>= 3.0, < 4.3)
128
+ activesupport (>= 3.0, < 4.3)
129
+ railties (>= 3.0, < 4.3)
130
+ rspec-core (~> 3.3.0)
131
+ rspec-expectations (~> 3.3.0)
132
+ rspec-mocks (~> 3.3.0)
133
+ rspec-support (~> 3.3.0)
134
+ rspec-support (3.3.0)
135
+ simplecov (0.10.0)
136
+ docile (~> 1.1.0)
137
+ json (~> 1.8)
138
+ simplecov-html (~> 0.10.0)
139
+ simplecov-html (0.10.0)
140
+ sprockets (3.2.0)
141
+ rack (~> 1.0)
142
+ sprockets-rails (2.3.2)
143
+ actionpack (>= 3.0)
144
+ activesupport (>= 3.0)
145
+ sprockets (>= 2.8, < 4.0)
146
+ sqlite3 (1.3.10)
147
+ term-ansicolor (1.3.2)
148
+ tins (~> 1.0)
149
+ thor (0.19.1)
150
+ thread_safe (0.3.5)
151
+ tins (1.5.4)
152
+ tzinfo (1.2.2)
153
+ thread_safe (~> 0.1)
154
+ unf (0.1.4)
155
+ unf_ext
156
+ unf_ext (0.0.7.1)
157
+
158
+ PLATFORMS
159
+ ruby
160
+
161
+ DEPENDENCIES
162
+ bundler (~> 1.10)
163
+ coveralls
164
+ factory_girl_rails
165
+ kaizan!
166
+ rake (~> 10.0)
167
+ rspec
168
+ rspec-html-matchers
169
+ rspec-rails
170
+ sqlite3
171
+
172
+ BUNDLED WITH
173
+ 1.10.3
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 mmmpa
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.md ADDED
@@ -0,0 +1,41 @@
1
+ # Kaizan
2
+
3
+ Kaizan(改ざん)はActionViewのテンプレート内で、下の方から上の方の指定領域に文字列を書き込むために書かれました。
4
+
5
+ `altering_anchor`で場所を指定しておいて`alter_past`で書き込みます。
6
+
7
+ ```html
8
+ <h1>モデルたち <%= altering_anchor :displayed %>/<%= @models.count %></h1>
9
+ <ul>
10
+ <% displayed_count = 0 %>
11
+ <%= @models.each do |model| %>
12
+ <li><%= if model.display?
13
+ displayed += 1
14
+ model.full_name
15
+ else
16
+ '非公開'
17
+ end %></li>
18
+ <% end %>
19
+ </ul>
20
+ <% alter_past :displayed, displayed_count %>
21
+ ```
22
+
23
+ ```html
24
+ <h1>モデルたち 3/5</h1>
25
+ <ul>
26
+ <li>モデル太郎</li>
27
+ <li>非公開</li>
28
+ <li>モデル三郎</li>
29
+ <li>モデル史郎</li>
30
+ <li>非公開</li>
31
+ </ul>
32
+ ```
33
+ です。
34
+
35
+ ## Installation
36
+
37
+ ```ruby
38
+ gem 'kaizan'
39
+ ```
40
+
41
+ $ bundle install
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ task :default => :spec
4
+ RSpec::Core::RakeTask.new
data/kaizan.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "kaizan/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "kaizan"
9
+ spec.version = Kaizan::VERSION
10
+ spec.authors = ["mmmpa"]
11
+ spec.email = ["mmmpa.mmmpa@gmail.com"]
12
+ spec.homepage = "http://mmmpa.net"
13
+ spec.summary = "Replace string in SafeBuffer safety."
14
+ spec.description = "Replace string in SafeBuffer safety."
15
+ spec.license = "MIT"
16
+
17
+ spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
18
+
19
+ spec.files = `git ls-files`.split("\n")
20
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+ spec.add_dependency "rails", "~> 4.2.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "sqlite3"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "rspec-rails"
30
+ spec.add_development_dependency 'rspec-html-matchers'
31
+ spec.add_development_dependency "factory_girl_rails"
32
+ spec.add_development_dependency "coveralls"
33
+ end
data/lib/kaizan.rb ADDED
@@ -0,0 +1,73 @@
1
+ module Kaizan
2
+ refine String do
3
+ alias :gsub_not_safety! :gsub!
4
+ end
5
+ end
6
+
7
+ module ActionView
8
+ using Kaizan
9
+
10
+ module Helpers
11
+ def alter_past(name, content)
12
+ output_buffer.alter_past!(name, content)
13
+ end
14
+
15
+
16
+ def altering_anchor(name = nil)
17
+ output_buffer.register_anchor(name)
18
+ end
19
+ end
20
+
21
+ class OutputBuffer
22
+
23
+ attr_accessor :altering_anchor, :anonymous_anchor
24
+
25
+
26
+ def initialize(*)
27
+ super
28
+
29
+ self.altering_anchor = {}
30
+ self.anonymous_anchor = []
31
+ end
32
+
33
+
34
+ def alter_past!(name, content)
35
+ return unless (anchor = detect_anchor(name)).present?
36
+ gsub_not_safety!(anchor, alter_string_safety(content))
37
+ end
38
+
39
+
40
+ def alter_string_safety(content)
41
+ content.html_safe? ? content.to_s : html_escape_interpolated_argument_force(content.to_s)
42
+ end
43
+
44
+
45
+ def register_anchor(name = nil)
46
+ generate_anchor(name).tap { |anchor|
47
+ anonymous_anchor.push(anchor)
48
+ altering_anchor[name] = anchor if name.present?
49
+ }.html_safe
50
+ end
51
+
52
+
53
+ private
54
+
55
+ def detect_anchor(name)
56
+ name.is_a?(Fixnum) ? anonymous_anchor[name] : altering_anchor[name]
57
+ end
58
+
59
+
60
+ def generate_anchor(name = nil)
61
+ if name && altering_anchor[name]
62
+ altering_anchor[name]
63
+ else
64
+ "<!-- altering_anchor:#{SecureRandom.hex(16)} -->"
65
+ end
66
+ end
67
+
68
+
69
+ def html_escape_interpolated_argument_force(arg)
70
+ arg.to_s.gsub(ERB::Util::HTML_ESCAPE_REGEXP, ERB::Util::HTML_ESCAPE)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Kaizan
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :kaizan do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.