utopia 1.9.11 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +3 -2
  3. data/.gitignore +4 -1
  4. data/.rspec +1 -0
  5. data/.travis.yml +4 -0
  6. data/.yardopts +2 -0
  7. data/Gemfile +8 -1
  8. data/README.md +2 -2
  9. data/Rakefile +10 -10
  10. data/benchmarks/call_vs_check.rb +36 -0
  11. data/benchmarks/const_vs_hash.rb +33 -0
  12. data/documentation/Gemfile +5 -0
  13. data/documentation/Guardfile +20 -0
  14. data/documentation/config.ru +6 -13
  15. data/documentation/config/puma.rb +20 -0
  16. data/documentation/pages/_editor.xnode +64 -0
  17. data/documentation/pages/_heading.xnode +2 -2
  18. data/documentation/pages/_page.xnode +1 -2
  19. data/documentation/pages/errors/exception.xnode +3 -3
  20. data/documentation/pages/errors/file-not-found.xnode +3 -3
  21. data/documentation/pages/wiki/bower-integration/content.md +1 -1
  22. data/documentation/pages/wiki/content.md +6 -8
  23. data/documentation/pages/wiki/controller.rb +3 -3
  24. data/documentation/pages/wiki/edit.xnode +7 -19
  25. data/documentation/pages/wiki/middleware/content/content.md +4 -10
  26. data/documentation/pages/wiki/{controller → middleware/controller}/actions/content.md +0 -0
  27. data/documentation/pages/wiki/{controller → middleware/controller}/links.yaml +0 -0
  28. data/documentation/pages/wiki/{controller → middleware/controller}/rewrite/content.md +3 -3
  29. data/documentation/pages/wiki/show.xnode +4 -6
  30. data/documentation/pages/wiki/updating-utopia/content.md +55 -0
  31. data/documentation/pages/wiki/your-first-page/content.md +5 -3
  32. data/documentation/public/materials +1 -0
  33. data/lib/utopia.rb +3 -4
  34. data/lib/utopia/command.rb +4 -284
  35. data/lib/utopia/command/server.rb +115 -0
  36. data/lib/utopia/command/setup.rb +78 -0
  37. data/lib/utopia/command/site.rb +183 -0
  38. data/lib/utopia/content.rb +83 -59
  39. data/lib/utopia/content/{transaction.rb → document.rb} +116 -110
  40. data/lib/utopia/content/link.rb +7 -2
  41. data/lib/utopia/content/links.rb +2 -1
  42. data/lib/utopia/content/markup.rb +7 -2
  43. data/lib/utopia/{tags/deferred.rb → content/namespace.rb} +25 -6
  44. data/lib/utopia/content/node.rb +74 -76
  45. data/lib/utopia/content/response.rb +22 -3
  46. data/lib/utopia/content/tags.rb +66 -0
  47. data/lib/utopia/controller.rb +10 -18
  48. data/lib/utopia/controller/actions.rb +10 -0
  49. data/lib/utopia/controller/base.rb +2 -1
  50. data/lib/utopia/controller/respond.rb +1 -1
  51. data/lib/utopia/controller/rewrite.rb +8 -4
  52. data/lib/utopia/exceptions.rb +1 -0
  53. data/lib/utopia/exceptions/handler.rb +7 -2
  54. data/lib/utopia/exceptions/mailer.rb +33 -12
  55. data/lib/utopia/{tags/node.rb → extensions/array_split.rb} +11 -9
  56. data/lib/utopia/{tags/environment.rb → extensions/date_comparisons.rb} +24 -14
  57. data/lib/utopia/http.rb +2 -0
  58. data/lib/utopia/locale.rb +1 -0
  59. data/lib/utopia/localization.rb +37 -28
  60. data/lib/utopia/logger.rb +1 -0
  61. data/lib/utopia/logger/compact_formatter.rb +1 -0
  62. data/lib/utopia/middleware.rb +11 -1
  63. data/lib/utopia/path.rb +1 -0
  64. data/lib/utopia/path/matcher.rb +14 -2
  65. data/lib/utopia/redirection.rb +13 -16
  66. data/lib/utopia/session.rb +14 -6
  67. data/lib/utopia/setup.rb +3 -1
  68. data/lib/utopia/static.rb +11 -12
  69. data/lib/utopia/version.rb +1 -1
  70. data/setup/server/git/hooks/post-receive +0 -4
  71. data/setup/site/.gitignore +9 -0
  72. data/setup/site/.rspec +1 -0
  73. data/setup/site/Gemfile +4 -0
  74. data/setup/site/Guardfile +17 -0
  75. data/setup/site/Rakefile +2 -2
  76. data/setup/site/config.ru +5 -12
  77. data/setup/site/pages/_heading.xnode +2 -2
  78. data/setup/site/pages/_page.xnode +1 -1
  79. data/setup/site/pages/errors/exception.xnode +3 -3
  80. data/setup/site/pages/errors/file-not-found.xnode +3 -3
  81. data/setup/site/pages/welcome/index.xnode +3 -3
  82. data/setup/site/public/_static/site.css +4 -0
  83. data/setup/site/spec/spec_helper.rb +29 -0
  84. data/setup/site/tasks/deploy.rake +13 -0
  85. data/setup/site/tasks/development.rake +34 -0
  86. data/setup/site/tasks/environment.rake +17 -0
  87. data/spec/mock_node.rb +15 -0
  88. data/spec/spec_helper.rb +29 -0
  89. data/{lib/utopia/extensions/date.rb → spec/utopia/content/document_spec.rb} +31 -21
  90. data/spec/utopia/content/markup_spec.rb +2 -2
  91. data/spec/utopia/content/{tag_spec.rb → namespace_spec.rb} +17 -10
  92. data/spec/utopia/content/tags_spec.rb +80 -0
  93. data/spec/utopia/content_spec.rb +1 -1
  94. data/spec/utopia/content_spec.ru +1 -6
  95. data/spec/utopia/content_spec/_heading.xnode +1 -1
  96. data/spec/utopia/content_spec/content/test-partial.xnode +1 -1
  97. data/spec/utopia/content_spec/index.xnode +1 -1
  98. data/spec/utopia/controller/middleware_spec.ru +1 -3
  99. data/spec/utopia/controller/respond_spec.rb +2 -22
  100. data/spec/utopia/controller/respond_spec.ru +1 -5
  101. data/spec/utopia/controller/respond_spec/errors/file-not-found.xnode +7 -6
  102. data/spec/utopia/exceptions/handler_spec.ru +1 -2
  103. data/spec/utopia/exceptions/mailer_spec.ru +1 -2
  104. data/spec/utopia/extensions_spec.rb +2 -2
  105. data/spec/utopia/localization_spec.ru +1 -2
  106. data/spec/utopia/performance_spec.rb +2 -6
  107. data/spec/utopia/performance_spec/config.ru +5 -12
  108. data/spec/utopia/performance_spec/pages/_heading.xnode +2 -2
  109. data/spec/utopia/performance_spec/pages/_page.xnode +1 -1
  110. data/spec/utopia/performance_spec/pages/errors/exception.xnode +3 -3
  111. data/spec/utopia/performance_spec/pages/errors/file-not-found.xnode +3 -3
  112. data/spec/utopia/performance_spec/pages/welcome/index.xnode +3 -3
  113. data/spec/utopia/setup_spec.rb +79 -15
  114. data/utopia.gemspec +3 -3
  115. metadata +41 -27
  116. data/.simplecov +0 -9
  117. data/documentation/pages/welcome/index.xnode +0 -41
  118. data/lib/utopia/content/tag.rb +0 -90
  119. data/lib/utopia/extensions/array.rb +0 -29
  120. data/lib/utopia/tags/override.rb +0 -33
  121. data/setup/site/.simplecov +0 -9
  122. data/setup/site/tasks/test.rake +0 -10
  123. data/setup/site/tasks/utopia.rake +0 -41
  124. data/spec/utopia/controller/respond_spec/rewrite/controller.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d1fd4dea2d181c046c412089844360517e6f423
4
- data.tar.gz: 2a778d65e0224bdb6415e5db6c3967e417913749
3
+ metadata.gz: 944c3e8fb35114656d9bf4f5628d6c4ecf569015
4
+ data.tar.gz: b34c396bc981f396faee6d49ace329141d3c5d20
5
5
  SHA512:
6
- metadata.gz: 460ef64a197ce840c44b42cc0239249fc003e039daa5cec56b8676882b3a5b63e1b7d7a433c20f5a01a7d62f2117a46887f871267265091205d07bc44725d453
7
- data.tar.gz: c26adcc4d5cba8e030ed842e6d329caec9f118565e328520135b635641cee559a67726dc459371c57f71c41f792f5f23751de0f26016112c3c341bbb1ebf8556
6
+ metadata.gz: 969bb2a0804488b5f72ea3b1d5652a5219cd1f865a6e3652dcb3bd0794f67de48b1d0ddaf8f2df4796ccc396b92b85d0205ed1e8c800528857b3edb28de22a42
7
+ data.tar.gz: '022596c8e3262206412bd534e3c78fbeb127f310081381971e2567e51a42a7af91b6a64d60bb78226b940280fe0e274787c98352462081bcfc3c3edf76f2ac09'
@@ -1,3 +1,4 @@
1
1
  exclude_paths:
2
- - "documentation"
3
- - "setup"
2
+ - "documentation/**/*"
3
+ - "setup/**/*"
4
+ - "benchmarks/*"
data/.gitignore CHANGED
@@ -15,4 +15,7 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- .tags*
18
+ .tags*
19
+ documentation/run/*
20
+ documentation/public/code/*
21
+ .rspec_status
data/.rspec CHANGED
@@ -1,4 +1,5 @@
1
1
  --color
2
2
  --format documentation
3
3
  --backtrace
4
+ --require spec_helper
4
5
  --warnings
@@ -1,5 +1,7 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ dist: trusty
4
+ cache: bundler
3
5
  before_install:
4
6
  # For testing purposes:
5
7
  - git config --global user.email "samuel@oriontransfer.net"
@@ -8,6 +10,7 @@ rvm:
8
10
  - 2.2.4
9
11
  - 2.3.2
10
12
  - 2.4.0
13
+ - jruby-head
11
14
  - ruby-head
12
15
  - rbx-3.65
13
16
  env: COVERAGE=true BENCHMARK=true
@@ -15,3 +18,4 @@ matrix:
15
18
  allow_failures:
16
19
  - rvm: rbx-3.65
17
20
  - rvm: ruby-head
21
+ - rvm: jruby-head
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ --asset materials:materials
data/Gemfile CHANGED
@@ -7,16 +7,23 @@ group :development do
7
7
  gem 'pry'
8
8
  gem 'pry-coolline'
9
9
 
10
+ gem 'yard'
11
+
10
12
  gem 'kramdown'
11
13
 
12
14
  gem 'json'
15
+ gem 'msgpack'
13
16
  end
14
17
 
15
18
  group :test do
16
19
  gem 'benchmark-ips'
17
- gem 'ruby-prof'
20
+ gem 'ruby-prof', platforms: :mri
21
+
22
+ gem 'guard-puma'
18
23
 
19
24
  gem 'rack-test'
25
+ gem 'rack-freeze', '~> 1.2'
26
+
20
27
  gem 'simplecov'
21
28
  gem 'coveralls', require: false
22
29
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ![Utopia](materials/utopia.png?raw=true)
1
+ # ![Utopia Logo](materials/utopia.png?raw=true)
2
2
 
3
3
  Utopia is a website generation framework which provides a robust set of tools to build highly complex dynamic websites. It uses the filesystem heavily for content and provides functions for interacting with files and directories as structure representing the website.
4
4
 
@@ -45,7 +45,7 @@ There is an excellent documentation wiki included with the source code. Simply c
45
45
 
46
46
  Released under the MIT license.
47
47
 
48
- Copyright, 2015, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
48
+ Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
49
49
 
50
50
  Permission is hereby granted, free of charge, to any person obtaining a copy
51
51
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -1,17 +1,17 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
- begin
6
- require('simplecov/version')
7
- task.rspec_opts = %w{--require simplecov} if ENV['COVERAGE']
8
- rescue LoadError
9
- end
10
- end
4
+ RSpec::Core::RakeTask.new(:test)
11
5
 
12
6
  task :documentation do
13
- sh('bundle install')
14
- sh('cd documentation && rake')
7
+ sh('yard', '-o', "documentation/public/code")
8
+
9
+ Bundler.with_clean_env do
10
+ Dir.chdir('documentation') do
11
+ sh('bundle', 'install', '--quiet')
12
+ sh('bundle', 'exec', 'rake')
13
+ end
14
+ end
15
15
  end
16
16
 
17
- task :default => :spec
17
+ task :default => :test
@@ -0,0 +1,36 @@
1
+ require 'benchmark/ips'
2
+
3
+ class A
4
+ end
5
+
6
+ class B
7
+ def self.do
8
+ end
9
+ end
10
+
11
+ class C
12
+ def self.do
13
+ end
14
+ end
15
+
16
+ Benchmark.ips do |x|
17
+ x.report("responds_to? (nothing)") do |times|
18
+ while (times -= 1) >= 0
19
+ A.do if A.respond_to?(:do)
20
+ end
21
+ end
22
+
23
+ x.report("B (empty method)") do |times|
24
+ while (times -= 1) >= 0
25
+ B.do
26
+ end
27
+ end
28
+
29
+ x.report("responds_to? (empty method)") do |times|
30
+ while (times -= 1) >= 0
31
+ C.do if C.respond_to?(:do)
32
+ end
33
+ end
34
+
35
+ x.compare!
36
+ end
@@ -0,0 +1,33 @@
1
+ require 'benchmark/ips'
2
+
3
+ module Foo
4
+ class Bar
5
+ end
6
+ end
7
+
8
+
9
+ THINGS = {
10
+ 'Bar' => Foo::Bar
11
+ }
12
+
13
+ Benchmark.ips do |x|
14
+ x.report("const_get('Bar')") do |i|
15
+ while (i -= 1) > 0
16
+ Foo.const_get('Bar')
17
+ end
18
+ end
19
+
20
+ x.report("const_get(:Bar)") do |i|
21
+ while (i -= 1) > 0
22
+ Foo.const_get(:Bar)
23
+ end
24
+ end
25
+
26
+ x.report("Hash\#[]") do |i|
27
+ while (i -= 1) > 0
28
+ THINGS['Bar']
29
+ end
30
+ end
31
+
32
+ x.compare!
33
+ end
@@ -3,6 +3,8 @@ source "https://rubygems.org"
3
3
 
4
4
  gem "utopia", path: File.expand_path("../", __dir__)
5
5
 
6
+ gem "rack-freeze", "~> 1.2"
7
+
6
8
  gem "rake"
7
9
  gem "bundler"
8
10
 
@@ -11,6 +13,7 @@ gem "kramdown"
11
13
  group :development do
12
14
  # For `rake server`:
13
15
  gem "puma"
16
+ gem "guard-puma"
14
17
 
15
18
  # For `rake console`:
16
19
  gem "pry"
@@ -19,6 +22,8 @@ group :development do
19
22
  # For `rspec` testing:
20
23
  gem "rspec"
21
24
  gem "simplecov"
25
+
26
+ gem "launchy"
22
27
  end
23
28
 
24
29
  group :production do
@@ -0,0 +1,20 @@
1
+
2
+ group :development do
3
+ guard :puma, port: 4000 do
4
+ watch('Gemfile.lock')
5
+ watch('config.ru')
6
+ watch(%r{^config|lib|pages/.*})
7
+ end
8
+
9
+ # Open the documentation website when the command is run, once puma has started:
10
+ require 'launchy'
11
+ $first_time = true
12
+
13
+ url_path = 'run/url.txt'
14
+ watch(url_path) do
15
+ if $first_time
16
+ $first_time = false
17
+ Launchy.open(File.read(url_path))
18
+ end
19
+ end
20
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require_relative 'config/environment'
4
4
 
5
+ require 'rack/freeze'
6
+
5
7
  if RACK_ENV == :production
6
8
  # Handle exceptions in production with a error page and send an email notification:
7
9
  use Utopia::Exceptions::Handler
@@ -19,7 +21,7 @@ use Rack::Sendfile
19
21
  use Utopia::ContentLength
20
22
 
21
23
  use Utopia::Redirection::Rewrite,
22
- '/' => '/welcome/index'
24
+ '/' => '/wiki/index'
23
25
 
24
26
  use Utopia::Redirection::DirectoryIndex
25
27
 
@@ -29,22 +31,13 @@ use Utopia::Redirection::Errors,
29
31
  use Utopia::Localization,
30
32
  :default_locale => 'en',
31
33
  :locales => ['en', 'de', 'ja', 'zh'],
32
- :nonlocalized => ['/_static/', '/_cache/']
34
+ :ignore => ['/_static/', '/_cache/']
33
35
 
34
- use Utopia::Controller,
35
- cache_controllers: (RACK_ENV == :production),
36
- base: Utopia::Controller::Base
36
+ use Utopia::Controller
37
37
 
38
38
  use Utopia::Static
39
39
 
40
40
  # Serve dynamic content
41
- use Utopia::Content,
42
- cache_templates: (RACK_ENV == :production),
43
- tags: {
44
- 'deferred' => Utopia::Tags::Deferred,
45
- 'override' => Utopia::Tags::Override,
46
- 'node' => Utopia::Tags::Node,
47
- 'environment' => Utopia::Tags::Environment.for(RACK_ENV)
48
- }
41
+ use Utopia::Content
49
42
 
50
43
  run lambda { |env| [404, {}, []] }
@@ -0,0 +1,20 @@
1
+
2
+ # Configure "min" to be the minimum number of threads to use to answer
3
+ # requests and "max" the maximum.
4
+ threads 0,4
5
+
6
+ # Preload the application before starting the workers; this conflicts with
7
+ # phased restart feature. (off by default)
8
+ preload_app!
9
+
10
+ # This writes run/url.txt which allows us to watch and load the URL once puma has started.
11
+ get(:binds).tap do |binds|
12
+ urls = binds.grep(/tcp:\/\/0.0.0.0:(\d+)/).collect do
13
+ "http://localhost:#{$1}"
14
+ end
15
+
16
+ run_path = File.expand_path('../run', __dir__)
17
+
18
+ FileUtils.mkdir_p run_path
19
+ File.write(File.join(run_path, 'url.txt'), urls.first)
20
+ end
@@ -0,0 +1,64 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <?r response.do_not_cache! ?>
5
+
6
+ <?r if title = self[:title] ?>
7
+ <title>Editing #{title.gsub(/<.*?>/, "")}</title>
8
+ <?r else ?>
9
+ <title>Utopia</title>
10
+ <?r end ?>
11
+
12
+ <link rel="icon" type="image/png" href="/_static/icon.png" />
13
+ <link rel="stylesheet" href="/_static/site.css" type="text/css" media="screen" />
14
+
15
+ <script src="/_components/jquery/jquery.min.js"></script>
16
+
17
+ <style type="text/css">
18
+ .editor form {
19
+ position: absolute;
20
+
21
+ display: flex;
22
+ flex-direction: column;
23
+ align-items: center;
24
+
25
+ width: 100%;
26
+ height: 100%;
27
+ }
28
+
29
+ .editor .header {
30
+ flex-grow: 0;
31
+ width: 100%;
32
+
33
+ display: flex;
34
+ justify-content: space-between;
35
+ align-items: center;
36
+
37
+ box-shadow: 0px 1px 0.5rem rgba(0, 0, 0, 0.5);
38
+ z-index: 10;
39
+ }
40
+
41
+ .editor .header * {
42
+ margin: 0.5rem;
43
+ }
44
+
45
+ .editor textarea {
46
+ flex-grow: 1;
47
+ width: 100%;
48
+
49
+ resize: none;
50
+ outline: none;
51
+
52
+ box-sizing: border-box;
53
+ margin: 0; padding: 0.5rem;
54
+
55
+ border: none;
56
+ background: none;
57
+ }
58
+ </style>
59
+ </head>
60
+
61
+ <body class="editor">
62
+ <utopia:content/>
63
+ </body>
64
+ </html>
@@ -1,2 +1,2 @@
1
- <?r transaction.attributes[:title] ||= content ?>
2
- <h1><content/></h1>
1
+ <?r document.attributes[:title] ||= content ?>
2
+ <h1><utopia:content/></h1>
@@ -1,7 +1,6 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <?r response.content_type = "text/html; charset=utf-8" ?>
5
4
  <?r response.cache! ?>
6
5
 
7
6
  <?r if title = self[:title] ?>
@@ -33,7 +32,7 @@
33
32
  </header>
34
33
 
35
34
  <div id="page">
36
- <content />
35
+ <utopia:content/>
37
36
  </div>
38
37
  </body>
39
38
  </html>
@@ -1,5 +1,5 @@
1
- <page>
2
- <heading>Exception</heading>
1
+ <content:page>
2
+ <content:heading>Exception</content:heading>
3
3
 
4
4
  <p>It seems like something didn't quite work out as expected!</p>
5
- </page>
5
+ </content:page>
@@ -1,5 +1,5 @@
1
- <page>
2
- <heading>File Not Found</heading>
1
+ <content:page>
2
+ <content:heading>File Not Found</content:heading>
3
3
 
4
4
  <p>The file you requested is unfortunately not available at this time!</p>
5
- </page>
5
+ </content:page>
@@ -22,4 +22,4 @@ Then add the appropriate `<script>` tags to `pages/_page.xnode`:
22
22
 
23
23
  This task copies only the contents of the dist directory. This ensures that you only get files intended for distribution. If the bower package doesn't have a `dist` directory, the entire contents is copied.
24
24
 
25
- <listing rel="site" src="tasks/bower.rake" brush="ruby" />
25
+ <fragment:listing rel="site" src="tasks/bower.rake" brush="ruby" />
@@ -1,6 +1,6 @@
1
1
  # Utopia Documentation Wiki
2
2
 
3
- This wiki includes documentation and examples showing how to use Utopia.
3
+ This wiki includes documentation and examples showing how to use Utopia. You can also browse the [code documentation](/code/index.html) for more detail.
4
4
 
5
5
  ## Introduction Guide
6
6
 
@@ -8,9 +8,10 @@ Reading these pages in order will give you an overview of the design of Utopia,
8
8
 
9
9
  - [Development Environment Setup](development-environment-setup/)
10
10
  - [Server Setup](server-setup/)
11
- - [Your first page](your-first-page/)
11
+ - [Your First Page](your-first-page/)
12
12
  - [Installing JavaScript Libraries](bower-integration/)
13
13
  - [Website Tests](testing/)
14
+ - [Updating Your Site](updating-utopia/)
14
15
 
15
16
  ## Middleware
16
17
 
@@ -18,10 +19,7 @@ Reading these pages in order will give you an overview of the design of Utopia,
18
19
  - [Redirection](middleware/redirection/) — Redirect URL patterns and status codes.
19
20
  - [Localization](middleware/localization/) — Non-intrusive localization of resources.
20
21
  - [Controller](middleware/controller/) — Flexible nested controllers with efficient behaviour.
22
+ - [Controller Actions](middleware/controller/actions/) — Invoke named actions.
23
+ - [Controller Rewrite](middleware/controller/rewrite/) — Pattern match requests.
21
24
  - [Content](middleware/content/) — XML-style template engine with dynamic markup.
22
- - [Session](middleware/session/) — Session storage using encrypted client-side cookies.
23
-
24
- ## Controller Layers
25
-
26
- - [Controller Actions](controller/actions/)
27
- - [Controller Rewrite](controller/rewrite/)
25
+ - [Session](middleware/session/) — Session storage using encrypted client-side cookies.