utopia 2.20.1 → 2.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/bake/utopia/environment.rb +90 -0
  4. data/bake/utopia/node.rb +3 -1
  5. data/bake/utopia/server.rb +61 -0
  6. data/bake/utopia/shell.rb +3 -1
  7. data/bake/utopia/site.rb +188 -0
  8. data/bake/utopia/static.rb +3 -2
  9. data/bake/utopia.rb +3 -1
  10. data/lib/utopia/content/document.rb +2 -19
  11. data/lib/utopia/content/link.rb +4 -19
  12. data/lib/utopia/content/links.rb +2 -19
  13. data/lib/utopia/content/markup.rb +2 -19
  14. data/lib/utopia/content/namespace.rb +2 -19
  15. data/lib/utopia/content/node.rb +4 -20
  16. data/lib/utopia/content/response.rb +2 -19
  17. data/lib/utopia/content/tags.rb +2 -19
  18. data/lib/utopia/content.rb +2 -19
  19. data/lib/utopia/content_length.rb +2 -19
  20. data/lib/utopia/controller/actions.rb +2 -19
  21. data/lib/utopia/controller/base.rb +2 -19
  22. data/lib/utopia/controller/respond.rb +2 -19
  23. data/lib/utopia/controller/rewrite.rb +2 -19
  24. data/lib/utopia/controller/variables.rb +2 -19
  25. data/lib/utopia/controller.rb +2 -19
  26. data/lib/utopia/exceptions/handler.rb +2 -19
  27. data/lib/utopia/exceptions/mailer.rb +2 -19
  28. data/lib/utopia/exceptions.rb +2 -19
  29. data/lib/utopia/extensions/array_split.rb +3 -20
  30. data/lib/utopia/extensions/date_comparisons.rb +3 -20
  31. data/lib/utopia/http.rb +2 -19
  32. data/lib/utopia/locale.rb +2 -19
  33. data/lib/utopia/localization.rb +2 -19
  34. data/lib/utopia/logger.rb +2 -19
  35. data/lib/utopia/middleware.rb +2 -19
  36. data/lib/utopia/path/matcher.rb +2 -19
  37. data/lib/utopia/path.rb +2 -19
  38. data/lib/utopia/redirection.rb +2 -19
  39. data/lib/utopia/responder.rb +2 -19
  40. data/lib/utopia/session/lazy_hash.rb +2 -19
  41. data/lib/utopia/session/serialization.rb +2 -19
  42. data/lib/utopia/session.rb +3 -19
  43. data/lib/utopia/setup.rb +2 -19
  44. data/lib/utopia/shell.rb +2 -19
  45. data/lib/utopia/static/local_file.rb +2 -19
  46. data/lib/utopia/static/mime_types.rb +2 -19
  47. data/lib/utopia/static.rb +2 -19
  48. data/lib/utopia/version.rb +3 -20
  49. data/lib/utopia.rb +3 -20
  50. data/license.md +25 -0
  51. data/readme.md +44 -0
  52. data/setup/site/.gitignore +0 -1
  53. data/setup/site/Guardfile +13 -13
  54. data/setup/site/bake.rb +3 -1
  55. data/setup/site/config/environment.rb +3 -0
  56. data/setup/site/config/{README.md → readme.md} +0 -0
  57. data/setup/site/config/sus.rb +10 -0
  58. data/setup/site/falcon.rb +3 -0
  59. data/setup/site/fixtures/website.rb +39 -0
  60. data/setup/site/gems.rb +8 -7
  61. data/setup/site/{README.md → readme.md} +0 -0
  62. data/setup/site/test/website.rb +28 -0
  63. data.tar.gz.sig +0 -0
  64. metadata +59 -62
  65. metadata.gz.sig +0 -0
  66. data/bake/utopia/test.rb +0 -10
  67. data/bin/utopia +0 -25
  68. data/lib/utopia/command/environment.rb +0 -93
  69. data/lib/utopia/command/server.rb +0 -113
  70. data/lib/utopia/command/site.rb +0 -233
  71. data/lib/utopia/command.rb +0 -67
  72. data/setup/site/.rspec +0 -4
  73. data/setup/site/spec/spec_helper.rb +0 -16
  74. data/setup/site/spec/website_context.rb +0 -54
  75. data/setup/site/spec/website_spec.rb +0 -25
@@ -1,233 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'fileutils'
24
- require 'find'
25
-
26
- require 'samovar'
27
-
28
- module Utopia
29
- module Command
30
- # This path must point to utopia/setup in the gem source.
31
- SETUP_ROOT = File.expand_path("../../../setup", __dir__)
32
-
33
- # Local site setup commands.
34
- class Site < Samovar::Command
35
- # Configuration files which should be installed/updated:
36
- CONFIGURATION_FILES = ['.gitignore', 'config.ru', 'config/environment.rb', 'falcon.rb', 'gems.rb', 'Guardfile', 'bake.rb', 'spec/spec_helper.rb', 'spec/website_context.rb', 'spec/website_spec.rb']
37
-
38
- # Directories that should exist:
39
- DIRECTORIES = ["config", "lib", "pages", "public", "tasks", "spec"]
40
-
41
- # Directories that should be removed during upgrade process:
42
- OLD_PATHS = ["access_log", "cache", "tmp", "Rakefile", "tasks", ".bowerrc"]
43
-
44
- # The root directory of the template site:
45
- ROOT = File.join(SETUP_ROOT, 'site')
46
-
47
- # Create a local site.
48
- class Create < Samovar::Command
49
- self.description = "Create a new local Utopia website using the default template."
50
-
51
- def call
52
- destination_root = parent.root
53
-
54
- $stderr.puts "Setting up initial site in #{destination_root} for Utopia v#{Utopia::VERSION}..."
55
-
56
- DIRECTORIES.each do |directory|
57
- FileUtils.mkdir_p(File.join(destination_root, directory))
58
- end
59
-
60
- Find.find(ROOT) do |source_path|
61
- # What is this doing?
62
- destination_path = File.join(destination_root, source_path[ROOT.size..-1])
63
-
64
- if File.directory?(source_path)
65
- FileUtils.mkdir_p(destination_path)
66
- else
67
- unless File.exist? destination_path
68
- FileUtils.copy_entry(source_path, destination_path)
69
- end
70
- end
71
- end
72
-
73
- CONFIGURATION_FILES.each do |configuration_file|
74
- destination_path = File.join(destination_root, configuration_file)
75
-
76
- if File.exist?(destination_path)
77
- buffer = File.read(destination_path).gsub('$UTOPIA_VERSION', Utopia::VERSION)
78
- File.open(destination_path, "w") { |file| file.write(buffer) }
79
- else
80
- warn "Could not open #{destination_path}, maybe it should be removed from CONFIGURATION_FILES?"
81
- end
82
- end
83
-
84
- Dir.chdir(destination_root) do
85
- puts "Setting up site in #{destination_root}..."
86
-
87
- if `which bundle`.strip != ''
88
- puts "Generating initial package list with bundle..."
89
- system("bundle", "install") or fail "could not install bundled gems"
90
- end
91
-
92
- if `which git`.strip == ""
93
- $stderr.puts "Now is a good time to learn about git: http://git-scm.com/"
94
- elsif !File.exist?('.git')
95
- puts "Setting up git repository..."
96
- system("git", "init") or fail "could not create git repository"
97
- system("git", "add", ".") or fail "could not add all files"
98
- system("git", "commit", "-q", "-m", "Initial Utopia v#{Utopia::VERSION} site.") or fail "could not commit files"
99
- end
100
- end
101
-
102
- Environment.defaults(destination_root)
103
-
104
- name = `git config user.name || whoami`.chomp
105
-
106
- puts
107
- puts " #{name},".ljust(78)
108
- puts "Thank you for using Utopia!".center(78)
109
- puts "We sincerely hope that Utopia helps to".center(78)
110
- puts "make your life easier and more enjoyable.".center(78)
111
- puts ""
112
- puts "To start the development server, run:".center(78)
113
- puts "bake utopia:development".center(78)
114
- puts ""
115
- puts "For extreme productivity, please consult the online documentation".center(78)
116
- puts "https://github.com/socketry/utopia".center(78)
117
- puts " ~ Samuel. ".rjust(78)
118
- end
119
- end
120
-
121
- # Update a local site.
122
- class Update < Samovar::Command
123
- self.description = "Upgrade an existing site to use the latest configuration files from the template."
124
-
125
- # Move legacy `pages/_static` to `public/_static`.
126
- def move_static!
127
- # If public/_static doens't exist, we are done.
128
- return unless File.exist? 'pages/_static'
129
-
130
- if File.exist? 'public/_static'
131
- if File.lstat("public/_static").symlink?
132
- FileUtils.rm_f "public/_static"
133
- else
134
- warn "Can't move pages/_static to public/_static, destination already exists."
135
- return
136
- end
137
- end
138
-
139
- # One more sanity check:
140
- if File.directory? 'pages/_static'
141
- system("git", "mv", "pages/_static", "public/")
142
- end
143
- end
144
-
145
- # Move `Gemfile` to `gems.rb`.
146
- def update_gemfile!
147
- # If `Gemfile` doens't exist, we are done:
148
- return unless File.exist?('Gemfile')
149
-
150
- system("git", "mv", "Gemfile", "gems.rb")
151
- system("git", "mv", "Gemfile.lock", "gems.locked")
152
- end
153
-
154
- def call
155
- destination_root = parent.root
156
- branch_name = "utopia-upgrade-#{Utopia::VERSION}"
157
-
158
- $stderr.puts "Upgrading #{destination_root}..."
159
-
160
- Dir.chdir(destination_root) do
161
- system('git', 'checkout', '-b', branch_name) or fail "could not change branch"
162
- end
163
-
164
- DIRECTORIES.each do |directory|
165
- FileUtils.mkdir_p(File.join(destination_root, directory))
166
- end
167
-
168
- OLD_PATHS.each do |path|
169
- path = File.join(destination_root, path)
170
- $stderr.puts "\tRemoving #{path}..."
171
- FileUtils.rm_rf(path)
172
- end
173
-
174
- CONFIGURATION_FILES.each do |configuration_file|
175
- source_path = File.join(Site::ROOT, configuration_file)
176
- destination_path = File.join(destination_root, configuration_file)
177
-
178
- $stderr.puts "Updating #{destination_path}..."
179
-
180
- FileUtils.copy_entry(source_path, destination_path)
181
- buffer = File.read(destination_path).gsub('$UTOPIA_VERSION', Utopia::VERSION)
182
- File.open(destination_path, "w") { |file| file.write(buffer) }
183
- end
184
-
185
- Environment.defaults(destination_root)
186
-
187
- begin
188
- Dir.chdir(destination_root) do
189
- # Stage any files that have been changed or removed:
190
- system("git", "add", "-u") or fail "could not add files"
191
-
192
- # Stage any new files that we have explicitly added:
193
- system("git", "add", *Site::CONFIGURATION_FILES) or fail "could not add files"
194
-
195
- move_static!
196
- update_gemfile!
197
-
198
- # Commit all changes:
199
- system("git", "commit", "-m", "Upgrade to utopia #{Utopia::VERSION}.") or fail "could not commit changes"
200
-
201
- # Checkout master..
202
- system("git", "checkout", "master") or fail "could not checkout master"
203
-
204
- # and merge:
205
- system("git", "merge", "--squash", "--no-commit", branch_name) or fail "could not merge changes"
206
- end
207
- rescue RuntimeError
208
- $stderr.puts "** Detected error with upgrade, reverting changes. Some new files may still exist in tree. **"
209
-
210
- system("git", "checkout", "master")
211
- ensure
212
- system("git", "branch", "-D", branch_name)
213
- end
214
- end
215
- end
216
-
217
- nested :command, {
218
- 'create' => Create,
219
- 'update' => Update
220
- }
221
-
222
- self.description = "Manage local utopia sites."
223
-
224
- def root
225
- @parent.root
226
- end
227
-
228
- def call
229
- @command.call
230
- end
231
- end
232
- end
233
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require_relative 'version'
24
-
25
- require_relative 'command/site'
26
- require_relative 'command/server'
27
- require_relative 'command/environment'
28
-
29
- module Utopia
30
- module Command
31
- def self.call(*arguments)
32
- Top.call(*arguments)
33
- end
34
-
35
- # The top level utopia command.
36
- class Top < Samovar::Command
37
- self.description = "A website development and deployment framework."
38
-
39
- options do
40
- option '-i/--in/--root <path>', "Work in the given root directory."
41
- option '-h/--help', "Print out help information."
42
- option '-v/--version', "Print out the application version."
43
- end
44
-
45
- nested :command, {
46
- 'site' => Site,
47
- 'server' => Server,
48
- 'environment' => Environment
49
- }
50
-
51
- # The root directory for the site.
52
- def root
53
- File.expand_path(@options.fetch(:root, ''), Dir.getwd)
54
- end
55
-
56
- def call
57
- if @options[:version]
58
- puts "#{self.name} v#{VERSION}"
59
- elsif @options[:help]
60
- print_usage(output: $stdout)
61
- else
62
- @command.call
63
- end
64
- end
65
- end
66
- end
67
- end
data/setup/site/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --backtrace
3
- --warnings
4
- --require spec_helper
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/setup'
4
- require 'covered/rspec'
5
- require 'variant'
6
-
7
- Variant.force!(:testing)
8
-
9
- RSpec.configure do |config|
10
- # Enable flags like --only-failures and --next-failure
11
- config.example_status_persistence_file_path = '.rspec_status'
12
-
13
- config.expect_with :rspec do |c|
14
- c.syntax = :expect
15
- end
16
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rack/test'
4
- require 'async/rspec/reactor'
5
-
6
- RSpec.shared_context "website" do
7
- include Rack::Test::Methods
8
-
9
- let(:rackup_path) {File.expand_path('../config.ru', __dir__)}
10
- let(:rackup_directory) {File.dirname(rackup_path)}
11
-
12
- let(:app) {Rack::Builder.parse_file(rackup_path).first}
13
- end
14
-
15
- RSpec.shared_examples_for "valid page" do |path|
16
- it "can access #{path}" do
17
- get path
18
-
19
- while last_response.redirect?
20
- follow_redirect!
21
- end
22
-
23
- expect(last_response.status).to be == 200
24
- end
25
- end
26
-
27
- RSpec.shared_context "server" do
28
- include_context "website"
29
- include_context Async::RSpec::Reactor
30
-
31
- before(:all) do
32
- require 'falcon/server'
33
- require 'async/io/unix_endpoint'
34
- require 'benchmark/http/spider'
35
- end
36
-
37
- before do
38
- @endpoint = Async::HTTP::Endpoint.parse("http://localhost", Async::IO::Endpoint.unix("server.ipc"))
39
-
40
- @server_task = reactor.async do
41
- middleware = Falcon::Server.middleware(app)
42
-
43
- server = Falcon::Server.new(middleware, endpoint)
44
-
45
- server.run
46
- end
47
- end
48
-
49
- after do
50
- @server_task.stop
51
- end
52
-
53
- let(:endpoint) {@endpoint}
54
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'website_context'
4
-
5
- RSpec.describe "website", timeout: 120 do
6
- include_context "server"
7
-
8
- let(:spider) {Benchmark::HTTP::Spider.new(depth: 128)}
9
- let(:statistics) {Benchmark::HTTP::Statistics.new}
10
-
11
- it "should be responsive" do
12
- Async::HTTP::Client.open(endpoint, connection_limit: 8) do |client|
13
- spider.fetch(statistics, client, endpoint.url) do |method, uri, response|
14
- if response.failure?
15
- Console.logger.error(endpoint) {"#{method} #{uri} -> #{response.status}"}
16
- end
17
- end.wait
18
- end
19
-
20
- statistics.print
21
-
22
- expect(statistics.samples).to be_any
23
- expect(statistics.failed).to be_zero
24
- end
25
- end