valid_route 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +19 -0
  4. data/lib/tasks/valid_route_tasks.rake +4 -0
  5. data/lib/valid_route/all.rb +2 -0
  6. data/lib/valid_route/route_formatter.rb +36 -0
  7. data/lib/valid_route/route_validator.rb +154 -0
  8. data/lib/valid_route/version.rb +3 -0
  9. data/lib/valid_route.rb +1 -0
  10. data/test/dummy/README.rdoc +28 -0
  11. data/test/dummy/Rakefile +6 -0
  12. data/test/dummy/app/assets/javascripts/application.js +15 -0
  13. data/test/dummy/app/assets/javascripts/others.js +2 -0
  14. data/test/dummy/app/assets/javascripts/pages.js +2 -0
  15. data/test/dummy/app/assets/javascripts/users.js +2 -0
  16. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  17. data/test/dummy/app/assets/stylesheets/others.css +4 -0
  18. data/test/dummy/app/assets/stylesheets/pages.css +4 -0
  19. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  20. data/test/dummy/app/assets/stylesheets/users.css +4 -0
  21. data/test/dummy/app/constraints/page_constraint.rb +9 -0
  22. data/test/dummy/app/constraints/user_constraint.rb +9 -0
  23. data/test/dummy/app/controllers/application_controller.rb +5 -0
  24. data/test/dummy/app/controllers/others_controller.rb +58 -0
  25. data/test/dummy/app/controllers/pages_controller.rb +58 -0
  26. data/test/dummy/app/controllers/users_controller.rb +58 -0
  27. data/test/dummy/app/helpers/application_helper.rb +2 -0
  28. data/test/dummy/app/helpers/others_helper.rb +2 -0
  29. data/test/dummy/app/helpers/pages_helper.rb +2 -0
  30. data/test/dummy/app/helpers/users_helper.rb +2 -0
  31. data/test/dummy/app/models/other.rb +19 -0
  32. data/test/dummy/app/models/page.rb +22 -0
  33. data/test/dummy/app/models/user.rb +22 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/app/views/others/_form.html.erb +29 -0
  36. data/test/dummy/app/views/others/edit.html.erb +6 -0
  37. data/test/dummy/app/views/others/index.html.erb +31 -0
  38. data/test/dummy/app/views/others/new.html.erb +5 -0
  39. data/test/dummy/app/views/others/show.html.erb +19 -0
  40. data/test/dummy/app/views/pages/_form.html.erb +29 -0
  41. data/test/dummy/app/views/pages/edit.html.erb +6 -0
  42. data/test/dummy/app/views/pages/index.html.erb +31 -0
  43. data/test/dummy/app/views/pages/new.html.erb +5 -0
  44. data/test/dummy/app/views/pages/show.html.erb +19 -0
  45. data/test/dummy/app/views/users/_form.html.erb +29 -0
  46. data/test/dummy/app/views/users/edit.html.erb +6 -0
  47. data/test/dummy/app/views/users/index.html.erb +31 -0
  48. data/test/dummy/app/views/users/new.html.erb +5 -0
  49. data/test/dummy/app/views/users/show.html.erb +19 -0
  50. data/test/dummy/bin/bundle +3 -0
  51. data/test/dummy/bin/rails +4 -0
  52. data/test/dummy/bin/rake +4 -0
  53. data/test/dummy/config/application.rb +24 -0
  54. data/test/dummy/config/boot.rb +5 -0
  55. data/test/dummy/config/database.yml +25 -0
  56. data/test/dummy/config/environment.rb +5 -0
  57. data/test/dummy/config/environments/development.rb +29 -0
  58. data/test/dummy/config/environments/production.rb +80 -0
  59. data/test/dummy/config/environments/test.rb +36 -0
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  62. data/test/dummy/config/initializers/inflections.rb +16 -0
  63. data/test/dummy/config/initializers/mime_types.rb +5 -0
  64. data/test/dummy/config/initializers/secret_token.rb +12 -0
  65. data/test/dummy/config/initializers/session_store.rb +3 -0
  66. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  67. data/test/dummy/config/locales/en.yml +23 -0
  68. data/test/dummy/config/routes.rb +22 -0
  69. data/test/dummy/config.ru +4 -0
  70. data/test/dummy/db/development.sqlite3 +0 -0
  71. data/test/dummy/db/migrate/20130504204336_create_pages.rb +13 -0
  72. data/test/dummy/db/migrate/20130505171048_create_users.rb +13 -0
  73. data/test/dummy/db/migrate/20130513145529_create_others.rb +11 -0
  74. data/test/dummy/db/schema.rb +40 -0
  75. data/test/dummy/db/seeds.rb +4 -0
  76. data/test/dummy/db/test.sqlite3 +0 -0
  77. data/test/dummy/log/development.log +8038 -0
  78. data/test/dummy/log/test.log +26031 -0
  79. data/test/dummy/public/404.html +58 -0
  80. data/test/dummy/public/422.html +58 -0
  81. data/test/dummy/public/500.html +57 -0
  82. data/test/dummy/public/favicon.ico +0 -0
  83. data/test/dummy/test/controllers/others_controller_test.rb +53 -0
  84. data/test/dummy/test/controllers/pages_controller_test.rb +54 -0
  85. data/test/dummy/test/controllers/users_controller_test.rb +52 -0
  86. data/test/dummy/test/helpers/others_helper_test.rb +4 -0
  87. data/test/dummy/test/helpers/pages_helper_test.rb +4 -0
  88. data/test/dummy/test/helpers/users_helper_test.rb +4 -0
  89. data/test/dummy/test/models/other_test.rb +7 -0
  90. data/test/dummy/test/models/page_test.rb +7 -0
  91. data/test/dummy/test/models/user_test.rb +7 -0
  92. data/test/dummy/test/valid_route/route_formatter_test.rb +48 -0
  93. data/test/dummy/test/valid_route/route_validator_test.rb +104 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/0204daa608dcc3d6010d17d5a3325dae +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/0800f54ee19cf3cee10b956fa9786799 +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/0f1e224003d74d132651ab92f55c07cd +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/36a0c7121af098cc05c1eb1e9b05c6fc +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
  103. data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
  104. data/test/dummy/tmp/cache/assets/development/sprockets/58e369b37e5157ea746a485eea17e9f7 +0 -0
  105. data/test/dummy/tmp/cache/assets/development/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
  106. data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  107. data/test/dummy/tmp/cache/assets/development/sprockets/7162e1034189ecdac520608cf2d65859 +0 -0
  108. data/test/dummy/tmp/cache/assets/development/sprockets/7ae10239eda2588a95fdcc7d871bef52 +0 -0
  109. data/test/dummy/tmp/cache/assets/development/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
  110. data/test/dummy/tmp/cache/assets/development/sprockets/8d5d60255600aa010a32e1d1a9bc6db6 +0 -0
  111. data/test/dummy/tmp/cache/assets/development/sprockets/b3d9b0e88cdded276ebdce333e338a85 +0 -0
  112. data/test/dummy/tmp/cache/assets/development/sprockets/cebc6db0bbb8120f430da3970b173d2f +0 -0
  113. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  114. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  115. data/test/dummy/tmp/cache/assets/development/sprockets/dd4918aca468e2fe7bf61814631a1758 +0 -0
  116. data/test/dummy/tmp/cache/assets/development/sprockets/ebb095504f281d4e6bc39c4e574e25b2 +0 -0
  117. data/test/dummy/tmp/cache/assets/development/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
  118. data/test/dummy/tmp/cache/assets/development/sprockets/f576841f662770908b35e6951e6900dd +0 -0
  119. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  120. data/test/dummy/tmp/cache/assets/development/sprockets/ff05efaf31ab618d1eae2cd81fe67315 +0 -0
  121. data/test/dummy/tmp/cache/assets/test/sprockets/0204daa608dcc3d6010d17d5a3325dae +0 -0
  122. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  123. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  124. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  125. data/test/dummy/tmp/cache/assets/test/sprockets/36a0c7121af098cc05c1eb1e9b05c6fc +0 -0
  126. data/test/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  127. data/test/dummy/tmp/cache/assets/test/sprockets/3d6a697f5610f9f9e1d5af4ce5c9d618 +0 -0
  128. data/test/dummy/tmp/cache/assets/test/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
  129. data/test/dummy/tmp/cache/assets/test/sprockets/58e369b37e5157ea746a485eea17e9f7 +0 -0
  130. data/test/dummy/tmp/cache/assets/test/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
  131. data/test/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  132. data/test/dummy/tmp/cache/assets/test/sprockets/717ea0077fd0f73e5d956e4902250d3a +0 -0
  133. data/test/dummy/tmp/cache/assets/test/sprockets/7ae10239eda2588a95fdcc7d871bef52 +0 -0
  134. data/test/dummy/tmp/cache/assets/test/sprockets/8733c94f79979ec907253d4bff6714a6 +0 -0
  135. data/test/dummy/tmp/cache/assets/test/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
  136. data/test/dummy/tmp/cache/assets/test/sprockets/8d5d60255600aa010a32e1d1a9bc6db6 +0 -0
  137. data/test/dummy/tmp/cache/assets/test/sprockets/b3d9b0e88cdded276ebdce333e338a85 +0 -0
  138. data/test/dummy/tmp/cache/assets/test/sprockets/c9f51f5d854353b135800b3f119d5a2f +0 -0
  139. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  140. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  141. data/test/dummy/tmp/cache/assets/test/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
  142. data/test/dummy/tmp/cache/assets/test/sprockets/f576841f662770908b35e6951e6900dd +0 -0
  143. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  144. data/test/dummy/tmp/cache/assets/test/sprockets/ff05efaf31ab618d1eae2cd81fe67315 +0 -0
  145. data/test/factories/others.rb +11 -0
  146. data/test/factories/pages.rb +23 -0
  147. data/test/factories/users.rb +34 -0
  148. data/test/test_helper.rb +17 -0
  149. metadata +401 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4afca94e7e2a46d340d2474c9f5b12b386ecf37
4
+ data.tar.gz: dfad34ddb57e360b42cb6f7c6fdc410dde50970f
5
+ SHA512:
6
+ metadata.gz: c8875fba33475ae9c7733a59127329e2ef89d46370acd6bbd13a2058ee4a164144cec08bb100efa74ae22b47396b9d40b01a1c55c5e461c6c2fc3aab37681f51
7
+ data.tar.gz: 5d78d64ddad6cdb9f7dc6b65e5b8be6f6fad450ab7c373f0d0ed75dfda7889121c03b2ae8f4970855c290a06ebb950c3395fc919b4fabd09fb51220d1e6397eb
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Vince Montalbano
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,19 @@
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
+ Bundler::GemHelper.install_tasks
8
+
9
+ require 'rake/testtask'
10
+
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = false
16
+ end
17
+
18
+
19
+ task default: :test
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :valid_route do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,2 @@
1
+ require 'valid_route/route_formatter'
2
+ require 'valid_route/route_validator'
@@ -0,0 +1,36 @@
1
+ module ValidRoute
2
+ class RouteFormatter
3
+ def initialize
4
+ @buffer = []
5
+ end
6
+
7
+ def result
8
+ @buffer #.compact.uniq
9
+ end
10
+
11
+ def section_title(title)
12
+ end
13
+
14
+ def section(routes)
15
+ @buffer << array_paths(routes)
16
+ @buffer.flatten!
17
+ end
18
+
19
+ def header(routes)
20
+ end
21
+
22
+ def no_routes
23
+ @buffer
24
+ end
25
+
26
+ private
27
+ def array_paths(routes)
28
+ regexp = "(.:format)"
29
+ paths = []
30
+ routes.map do |r|
31
+ paths << {path: r[:path].sub(regexp, ""), verb: r[:verb], reqs: r[:reqs] }
32
+ end
33
+ paths
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,154 @@
1
+ class RouteValidator < ActiveModel::EachValidator
2
+
3
+ def initialize(options)
4
+ super
5
+ scrub_options options
6
+ end
7
+
8
+ def validate_each(record, attribute, value)
9
+ # Get all Routes
10
+ inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
11
+ routes = inspector.format(ValidRoute::RouteFormatter.new)
12
+
13
+ routes = scrub_routes routes
14
+
15
+ conflicts = check_conflicts routes, record
16
+
17
+
18
+
19
+ unless conflicts.empty?
20
+ record.errors[attribute] << (@options[:message] || "route is taken")
21
+ end
22
+ end
23
+
24
+ private
25
+ def check_conflicts(routes, record)
26
+
27
+ # Get the Class of the record we want to validate
28
+ endpoint = record.class.name.underscore
29
+
30
+ conflicts = []
31
+
32
+ # Get the list of routes we want to create which may conflict with other routes based off of the controller
33
+ routes_to_create = []
34
+ routes.each { |result|
35
+ routes_to_create.push result if result[:reqs].include?(endpoint)
36
+ }
37
+
38
+
39
+ # Get all possibly conflicting paths (routes to the same path, unless it's a path for the current controller)
40
+ possible_conflicts = []
41
+ routes_to_create.each {|route_to_create|
42
+ routes.each {|route|
43
+ unless route == route_to_create
44
+ parameter = route_to_create[:path].split(/.*?(:[^\/]*)/).last || ""
45
+ substituted_route = route_to_create[:path].sub(parameter, record.to_param)
46
+ if (route[:path] == route_to_create[:path]) or (route[:path] == substituted_route)
47
+ possible_conflicts.push route
48
+ end
49
+ end
50
+ }
51
+
52
+ }
53
+
54
+ # if there is an already existing route for a non-show and non-edit action, add it to the list of conflicting paths
55
+ possible_conflicts.each {|route|
56
+ routes_to_create.each {|route_to_create|
57
+ unless (route[:reqs].include?("#show") or route[:reqs].include?("#edit"))
58
+ parameter = route_to_create[:path].split(/.*?(:[^\/]*)/).last || ""
59
+ substituted_route = route_to_create[:path].sub(parameter, record.to_param)
60
+ if (route[:path] == route_to_create[:path]) or (route[:path] == substituted_route)
61
+ conflicts.push route
62
+ end
63
+ end
64
+ }
65
+ }
66
+
67
+ # Check for existing records of other Classes' Show actions, add it to the conflicting paths if the record at that path already exists
68
+ possible_conflicts.each {|route|
69
+ routes_to_create.each {|route_to_create|
70
+ if route[:reqs].include?("#show") or route[:reqs].include?("#edit")
71
+ if route[:reqs].include?("/") # is this a namespaced route or anything?
72
+ route_controller_segments = route[:reqs].split(/^(.*\/)(.*)$/)
73
+ klass_underscored = route_controller_segments[0] + route_controller_segments[1].singularize
74
+ else
75
+ klass_underscored = route[:reqs].slice(/(.*)(#)(.*)/, 1).singularize
76
+ end
77
+ klass = klass_underscored.classify.constantize
78
+ if klass.exists?(record.to_param)
79
+ conflicts.push route unless klass.find(record.to_param).eql? record
80
+ end
81
+ if record.class.exists?(record.to_param)
82
+ conflicts.push route unless record.class.find(record.to_param).eql? record
83
+ end
84
+ end
85
+ }
86
+ }
87
+
88
+ conflicts
89
+ end
90
+
91
+ def scrub_options(options)
92
+ unless options[:reserved_routes].nil?
93
+ options[:reserved_routes].map! { |route_path|
94
+ route_path = "/" + route_path if route_path[0] != "/"
95
+ }
96
+ end
97
+
98
+ unless options[:unreserved_routes].nil?
99
+ options[:unreserved_routes].map! { |route_path|
100
+ route_path = "/" + route_path if route_path[0] != "/"
101
+ }
102
+ end
103
+ end
104
+
105
+ def scrub_routes(routes)
106
+
107
+ # Add the additional routes
108
+ unless @options[:reserved_routes].nil?
109
+ @options[:reserved_routes].each { |route_path|
110
+ # puts "valid_route:110 #{route_path}"
111
+ routes << {path: route_path, verb: 'GET', reqs: ''}
112
+ }
113
+ end
114
+
115
+ # Remove unreserved routes
116
+ unless @options[:unreserved_routes].nil?
117
+ routes.delete_if { |route|
118
+ route_included = false
119
+ @options[:unreserved_routes].each { |route_path|
120
+ # puts "valid_route:120 #{route[:path]} #{route_path}"
121
+ route_included = route_included || (route[:path] == route_path)
122
+ }
123
+ route_included
124
+ }
125
+ end
126
+
127
+ # Filter for matching GET requests only
128
+ routes.delete_if { |route|
129
+ delete = false
130
+ delete = route[:verb] != "GET" || delete
131
+ # delete = route[:reqs].include?("redirect") || delete
132
+ # delete
133
+ }
134
+
135
+ # Allow redirect paths
136
+ routes.each {|route|
137
+ if route[:reqs].include?("redirect")
138
+ redirected_path = route[:reqs].slice(/.*redirect\(\d*,\s([^\)]*)\)/, 1)
139
+ delete_original = false
140
+ routes.each {|route_to_match|
141
+ if route_to_match[:path] == redirected_path
142
+ redirected_route = route.clone
143
+ redirected_route[:reqs] = route_to_match[:reqs]
144
+ routes << redirected_route
145
+ delete_original = true
146
+ end
147
+ }
148
+ routes.delete route if delete_original
149
+ end
150
+ }
151
+
152
+ routes.compact.flatten.uniq
153
+ end
154
+ end
@@ -0,0 +1,3 @@
1
+ module ValidRoute
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'valid_route/all'
@@ -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>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,9 @@
1
+ # http://robotslacker.com/2012/01/rails-3-routes-configuration-dynamic-segments-constraints-and-scope/
2
+ class PageConstraint
3
+ def initialize
4
+ end
5
+
6
+ def matches?(request)
7
+ Page.exists?(request.path_parameters[:id])
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # http://robotslacker.com/2012/01/rails-3-routes-configuration-dynamic-segments-constraints-and-scope/
2
+ class UserConstraint
3
+ def initialize
4
+ end
5
+
6
+ def matches?(request)
7
+ User.exists?(request.path_parameters[:id])
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,58 @@
1
+ class OthersController < ApplicationController
2
+ before_action :set_other, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /others
5
+ def index
6
+ @others = Other.all
7
+ end
8
+
9
+ # GET /others/1
10
+ def show
11
+ end
12
+
13
+ # GET /others/new
14
+ def new
15
+ @other = Other.new
16
+ end
17
+
18
+ # GET /others/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /others
23
+ def create
24
+ @other = Other.new(other_params)
25
+
26
+ if @other.save
27
+ redirect_to @other, notice: 'Other was successfully created.'
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /others/1
34
+ def update
35
+ if @other.update(other_params)
36
+ redirect_to @other, notice: 'Other was successfully updated.'
37
+ else
38
+ render action: 'edit'
39
+ end
40
+ end
41
+
42
+ # DELETE /others/1
43
+ def destroy
44
+ @other.destroy
45
+ redirect_to others_url, notice: 'Other was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_other
51
+ @other = Other.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def other_params
56
+ params.require(:other).permit(:name, :permalink, :content)
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ class PagesController < ApplicationController
2
+ before_action :set_page, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /pages
5
+ def index
6
+ @pages = Page.all
7
+ end
8
+
9
+ # GET /pages/1
10
+ def show
11
+ end
12
+
13
+ # GET /pages/new
14
+ def new
15
+ @page = Page.new
16
+ end
17
+
18
+ # GET /pages/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /pages
23
+ def create
24
+ @page = Page.new(page_params)
25
+
26
+ if @page.save
27
+ redirect_to @page, notice: 'Page was successfully created.'
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /pages/1
34
+ def update
35
+ if @page.update(page_params)
36
+ redirect_to @page, notice: 'Page was successfully updated.'
37
+ else
38
+ render action: 'edit'
39
+ end
40
+ end
41
+
42
+ # DELETE /pages/1
43
+ def destroy
44
+ @page.destroy
45
+ redirect_to pages_url, notice: 'Page was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_page
51
+ @page = Page.find_by_permalink(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def page_params
56
+ params.require(:page).permit(:name, :permalink, :content)
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ class UsersController < ApplicationController
2
+ before_action :set_user, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /users
5
+ def index
6
+ @users = User.all
7
+ end
8
+
9
+ # GET /users/1
10
+ def show
11
+ end
12
+
13
+ # GET /users/new
14
+ def new
15
+ @user = User.new
16
+ end
17
+
18
+ # GET /users/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /users
23
+ def create
24
+ @user = User.new(user_params)
25
+
26
+ if @user.save
27
+ redirect_to @user, notice: 'User was successfully created.'
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /users/1
34
+ def update
35
+ if @user.update(user_params)
36
+ redirect_to @user, notice: 'User was successfully updated.'
37
+ else
38
+ render action: 'edit'
39
+ end
40
+ end
41
+
42
+ # DELETE /users/1
43
+ def destroy
44
+ @user.destroy
45
+ redirect_to users_url, notice: 'User was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_user
51
+ @user = User.find_by_username(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def user_params
56
+ params.require(:user).permit(:username, :password, :first_name)
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module OthersHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PagesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
@@ -0,0 +1,19 @@
1
+ class Other < ActiveRecord::Base
2
+ # rails g scaffold Other name:string permalink:string content:text
3
+
4
+ validates :permalink, :route => { unreserved_routes: ["pages"] }
5
+
6
+ validates_format_of :permalink, :without => /^\d/, :multiline => true
7
+
8
+ def self.find(input)
9
+ input.to_i == 0 ? find_by_permalink(input) : super(input)
10
+ end
11
+
12
+ def self.exists?(input)
13
+ input.to_i == 0 ? super(permalink: input) : super(input)
14
+ end
15
+
16
+ def to_param # overridden
17
+ self.permalink
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ class Page < ActiveRecord::Base
2
+ # rails g scaffold Page name:string permalink:string content:text slug:string
3
+
4
+ # extend FriendlyId
5
+ # friendly_id :permalink #, use: :slugged
6
+
7
+ validates :permalink, :route => {reserved_routes: ["reserved", "tommy"]}
8
+
9
+ validates_format_of :permalink, :without => /^\d/, :multiline => true
10
+
11
+ def self.find(input)
12
+ input.to_i == 0 ? find_by_permalink(input) : super(input)
13
+ end
14
+
15
+ def self.exists?(input)
16
+ input.to_i == 0 ? super(permalink: input) : super(input)
17
+ end
18
+
19
+ def to_param # overridden
20
+ self.permalink
21
+ end
22
+ end