utopia 0.12.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/Gemfile +6 -0
  4. data/README.md +48 -14
  5. data/Rakefile +5 -0
  6. data/bin/utopia +132 -15
  7. data/lib/utopia.rb +13 -10
  8. data/lib/utopia/content.rb +140 -0
  9. data/lib/utopia/content/link.rb +124 -0
  10. data/lib/utopia/content/links.rb +228 -0
  11. data/lib/utopia/content/node.rb +387 -0
  12. data/lib/utopia/content/processor.rb +128 -0
  13. data/lib/utopia/content/tag.rb +102 -0
  14. data/lib/utopia/controller.rb +137 -0
  15. data/lib/utopia/controller/action.rb +112 -0
  16. data/lib/utopia/controller/base.rb +174 -0
  17. data/lib/utopia/{middleware/controller → controller}/variables.rb +36 -38
  18. data/lib/utopia/exception_handler.rb +79 -0
  19. data/lib/utopia/extensions/array.rb +2 -2
  20. data/lib/utopia/localization.rb +143 -0
  21. data/lib/utopia/mail_exceptions.rb +136 -0
  22. data/lib/utopia/middleware.rb +7 -22
  23. data/lib/utopia/path.rb +150 -60
  24. data/lib/utopia/redirector.rb +152 -0
  25. data/lib/utopia/{extensions/hash.rb → session.rb} +4 -6
  26. data/lib/utopia/session/encrypted_cookie.rb +46 -48
  27. data/lib/utopia/{middleware/directory_index.rb → session/lazy_hash.rb} +44 -27
  28. data/lib/utopia/static.rb +255 -0
  29. data/lib/utopia/tags/deferred.rb +12 -8
  30. data/lib/utopia/tags/environment.rb +18 -6
  31. data/lib/utopia/tags/node.rb +12 -8
  32. data/lib/utopia/tags/override.rb +12 -12
  33. data/lib/utopia/version.rb +1 -1
  34. data/setup/.bowerrc +3 -0
  35. data/{lib/utopia/setup → setup}/Gemfile +1 -1
  36. data/setup/Rakefile +4 -0
  37. data/{lib/utopia/setup → setup}/cache/head/readme.txt +0 -0
  38. data/{lib/utopia/setup → setup}/cache/meta/readme.txt +0 -0
  39. data/setup/config.ru +64 -0
  40. data/{lib/utopia/setup → setup}/lib/readme.txt +0 -0
  41. data/{lib/utopia/setup → setup}/pages/_heading.xnode +0 -0
  42. data/{lib/utopia/setup → setup}/pages/_page.xnode +1 -1
  43. data/{lib/utopia/setup → setup}/pages/_static/icon.png +0 -0
  44. data/setup/pages/_static/site.css +70 -0
  45. data/{lib/utopia/setup → setup}/pages/errors/exception.xnode +0 -0
  46. data/{lib/utopia/setup → setup}/pages/errors/file-not-found.xnode +0 -0
  47. data/{lib/utopia/setup → setup}/pages/links.yaml +0 -0
  48. data/setup/pages/welcome/index.xnode +17 -0
  49. data/{lib/utopia/setup → setup}/public/readme.txt +0 -0
  50. data/spec/utopia/content/link_spec.rb +108 -0
  51. data/spec/utopia/content/links/foo/index.xnode +0 -0
  52. data/spec/utopia/content/links/foo/links.yaml +2 -0
  53. data/spec/utopia/content/links/foo/test.de.xnode +0 -0
  54. data/spec/utopia/content/links/foo/test.en.xnode +0 -0
  55. data/spec/utopia/content/links/links.yaml +9 -0
  56. data/spec/utopia/content/links/welcome.xnode +0 -0
  57. data/spec/utopia/content/localized/five/index.en.xnode +0 -0
  58. data/spec/utopia/content/localized/four/index.en.xnode +0 -0
  59. data/spec/utopia/content/localized/four/index.zh.xnode +0 -0
  60. data/spec/utopia/content/localized/four/links.yaml +4 -0
  61. data/spec/utopia/content/localized/links.yaml +16 -0
  62. data/spec/utopia/content/localized/one.xnode +0 -0
  63. data/spec/utopia/content/localized/three/index.xnode +0 -0
  64. data/spec/utopia/content/localized/two.en.xnode +0 -0
  65. data/spec/utopia/content/localized/two.zh.xnode +0 -0
  66. data/spec/utopia/content/node/ordered/first.xnode +0 -0
  67. data/spec/utopia/content/node/ordered/index.xnode +0 -0
  68. data/spec/utopia/content/node/ordered/links.yaml +4 -0
  69. data/spec/utopia/content/node/ordered/second.xnode +0 -0
  70. data/spec/utopia/content/node/related/foo.en.xnode +0 -0
  71. data/spec/utopia/content/node/related/foo.ja.xnode +0 -0
  72. data/spec/utopia/content/node/related/links.yaml +4 -0
  73. data/spec/utopia/content/node_spec.rb +63 -0
  74. data/spec/utopia/{middleware/content_spec.rb → content/processor_spec.rb} +34 -23
  75. data/spec/utopia/content_spec.rb +87 -0
  76. data/spec/utopia/content_spec.ru +10 -0
  77. data/spec/utopia/{middleware/controller_spec.rb → controller_spec.rb} +61 -16
  78. data/spec/utopia/controller_spec.ru +4 -0
  79. data/spec/utopia/extensions_spec.rb +6 -17
  80. data/spec/utopia/localization_spec.rb +60 -0
  81. data/spec/utopia/localization_spec.ru +11 -0
  82. data/{lib/utopia/tags.rb → spec/utopia/middleware_spec.rb} +8 -14
  83. data/spec/utopia/{middleware/content_root → pages}/_heading.xnode +0 -0
  84. data/spec/utopia/pages/content/_show-value.xnode +1 -0
  85. data/spec/utopia/pages/content/test-partial.xnode +1 -0
  86. data/spec/utopia/pages/controller/controller.rb +28 -0
  87. data/spec/utopia/pages/controller/index.xnode +1 -0
  88. data/spec/utopia/pages/controller/nested/controller.rb +4 -0
  89. data/spec/utopia/{middleware/content_root → pages}/index.xnode +0 -0
  90. data/spec/utopia/pages/localized.de.txt +1 -0
  91. data/spec/utopia/pages/localized.en.txt +1 -0
  92. data/spec/utopia/pages/localized.jp.txt +1 -0
  93. data/spec/utopia/pages/node/index.xnode +1 -0
  94. data/spec/utopia/pages/test.txt +1 -0
  95. data/spec/utopia/path_spec.rb +109 -0
  96. data/spec/utopia/rack_spec.rb +2 -0
  97. data/spec/utopia/session_spec.rb +82 -0
  98. data/spec/utopia/session_spec.ru +20 -0
  99. data/spec/utopia/spec_helper.rb +16 -0
  100. data/{lib/utopia/extensions/string.rb → spec/utopia/static_spec.rb} +24 -15
  101. data/spec/utopia/static_spec.ru +4 -0
  102. data/utopia.gemspec +3 -3
  103. metadata +138 -54
  104. data/lib/utopia/extensions/regexp.rb +0 -33
  105. data/lib/utopia/link.rb +0 -288
  106. data/lib/utopia/middleware/all.rb +0 -33
  107. data/lib/utopia/middleware/content.rb +0 -157
  108. data/lib/utopia/middleware/content/node.rb +0 -386
  109. data/lib/utopia/middleware/content/processor.rb +0 -123
  110. data/lib/utopia/middleware/controller.rb +0 -130
  111. data/lib/utopia/middleware/controller/action.rb +0 -121
  112. data/lib/utopia/middleware/controller/base.rb +0 -184
  113. data/lib/utopia/middleware/exception_handler.rb +0 -80
  114. data/lib/utopia/middleware/localization.rb +0 -147
  115. data/lib/utopia/middleware/localization/name.rb +0 -69
  116. data/lib/utopia/middleware/mail_exceptions.rb +0 -138
  117. data/lib/utopia/middleware/redirector.rb +0 -146
  118. data/lib/utopia/middleware/requester.rb +0 -126
  119. data/lib/utopia/middleware/static.rb +0 -295
  120. data/lib/utopia/setup.rb +0 -60
  121. data/lib/utopia/setup/config.ru +0 -47
  122. data/lib/utopia/setup/pages/_static/background.png +0 -0
  123. data/lib/utopia/setup/pages/_static/site.css +0 -48
  124. data/lib/utopia/setup/pages/welcome/index.xnode +0 -7
  125. data/lib/utopia/tag.rb +0 -105
  126. data/lib/utopia/tags/all.rb +0 -34
@@ -18,12 +18,16 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'utopia/tags'
22
-
23
- Utopia::Tags.create("deferred") do |transaction, state|
24
- id = state[:id].to_i
25
-
26
- procedure = transaction.parent.deferred[id]
27
-
28
- procedure.call(transaction, state)
21
+ module Utopia
22
+ module Tags
23
+ class Deferred
24
+ def self.call(transaction, state)
25
+ id = state[:id].to_i
26
+
27
+ procedure = transaction.parent.deferred[id]
28
+
29
+ procedure.call(transaction, state)
30
+ end
31
+ end
32
+ end
29
33
  end
@@ -18,12 +18,24 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'utopia/tags'
21
+ module Utopia
22
+ module Tags
23
+ class Environment
24
+ def self.for(environment)
25
+ self.new(environment)
26
+ end
27
+
28
+ def initialize(environment)
29
+ @environment = environment
30
+ end
31
+
32
+ def call(transaction, state)
33
+ only = state[:only].split(",").collect(&:to_sym) rescue []
22
34
 
23
- Utopia::Tags.create("env") do |transaction, state|
24
- only = state[:only].split(",").collect(&:to_sym) rescue []
25
-
26
- if defined?(UTOPIA_ENV) && only.include?(UTOPIA_ENV)
27
- transaction.parse_xml(state.content)
35
+ if defined?(@environment) and only.include?(@environment)
36
+ transaction.parse_xml(state.content)
37
+ end
38
+ end
39
+ end
28
40
  end
29
41
  end
@@ -18,12 +18,16 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'utopia/tags'
22
-
23
- Utopia::Tags.create("node") do |transaction, state|
24
- path = Utopia::Path.create(state[:path])
25
-
26
- node = transaction.lookup_node(path)
27
-
28
- transaction.render_node(node)
21
+ module Utopia
22
+ module Tags
23
+ class Node
24
+ def self.call(transaction, state)
25
+ path = Utopia::Path.create(state[:path])
26
+
27
+ node = transaction.lookup_node(path)
28
+
29
+ transaction.render_node(node)
30
+ end
31
+ end
32
+ end
29
33
  end
@@ -18,16 +18,16 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'utopia/tags'
22
-
23
- class Utopia::Tags::Override
24
- def self.tag_begin(transaction, state)
25
- state.overrides[state[:name]] = state[:with]
26
- end
27
-
28
- def self.call(transaction, state)
29
- transaction.parse_xml(state.content)
21
+ module Utopia
22
+ module Tags
23
+ class Override
24
+ def self.tag_begin(transaction, state)
25
+ state.overrides[state[:name]] = state[:with]
26
+ end
27
+
28
+ def self.call(transaction, state)
29
+ transaction.parse_xml(state.content)
30
+ end
31
+ end
30
32
  end
31
- end
32
-
33
- Utopia::Tags.register("override", Utopia::Tags::Override)
33
+ end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Utopia
22
- VERSION = "0.12.6"
22
+ VERSION = "1.0.0"
23
23
  end
@@ -0,0 +1,3 @@
1
+ {
2
+ "directory" : "public/_static/components"
3
+ }
@@ -6,5 +6,5 @@ gem "utopia", "~> $UTOPIA_VERSION"
6
6
  # gem "utopia-tags-google-analytics"
7
7
 
8
8
  group :development do
9
- gem "thin"
9
+ gem "puma"
10
10
  end
@@ -0,0 +1,4 @@
1
+
2
+ task :server do
3
+ system('puma')
4
+ end
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env rackup
2
+
3
+ # Setup default encoding:
4
+ Encoding.default_external = Encoding::UTF_8
5
+ Encoding.default_internal = Encoding::UTF_8
6
+
7
+ # Setup the server environment:
8
+ RACK_ENV = ENV.fetch('RACK_ENV', :development).to_sym unless defined?(RACK_ENV)
9
+
10
+ # Allow loading library code from lib directory:
11
+ $LOAD_PATH << File.expand_path("../lib", __FILE__)
12
+
13
+ require 'utopia'
14
+ require 'rack/cache'
15
+
16
+ if RACK_ENV == :production
17
+ use Utopia::ExceptionHandler, "/errors/exception"
18
+ use Utopia::MailExceptions
19
+ else
20
+ use Rack::ShowExceptions
21
+ end
22
+
23
+ use Rack::Sendfile
24
+
25
+ if RACK_ENV == :production
26
+ use Rack::Cache,
27
+ metastore: "file:#{Utopia::default_root("cache/meta")}",
28
+ entitystore: "file:#{Utopia::default_root("cache/body")}",
29
+ verbose: RACK_ENV == :development
30
+ end
31
+
32
+ use Rack::ContentLength
33
+
34
+ use Utopia::Redirector,
35
+ patterns: [
36
+ Utopia::Redirector::DIRECTORY_INDEX
37
+ ],
38
+ strings: {
39
+ '/' => '/welcome/index',
40
+ },
41
+ errors: {
42
+ 404 => "/errors/file-not-found"
43
+ }
44
+
45
+ use Utopia::Localization,
46
+ :default_locale => 'en',
47
+ :locales => ['en', 'de', 'ja', 'zh'],
48
+ :nonlocalized => ['/_static/', '/_cache/']
49
+
50
+ use Utopia::Controller,
51
+ cache_controllers: (RACK_ENV == :production)
52
+
53
+ use Utopia::Static
54
+
55
+ use Utopia::Content,
56
+ cache_templates: (RACK_ENV == :production),
57
+ tags: {
58
+ 'deferred' => Utopia::Tags::Deferred,
59
+ 'override' => Utopia::Tags::Override,
60
+ 'node' => Utopia::Tags::Node,
61
+ 'environment' => Utopia::Tags::Environment.for(RACK_ENV)
62
+ }
63
+
64
+ run lambda { |env| [404, {}, []] }
@@ -14,7 +14,7 @@
14
14
  <link rel="stylesheet" href="/_static/site.css" type="text/css" media="screen" />
15
15
  </head>
16
16
 
17
- <body>
17
+ <body class="#{attributes['class']}">
18
18
  <div id="header">
19
19
  </div>
20
20
 
@@ -0,0 +1,70 @@
1
+
2
+ body {
3
+ font-family: Verdana, Helvetica, Arial;
4
+ background-color: #ccc;
5
+ padding: 50px;
6
+ }
7
+
8
+ p {
9
+ color: #333;
10
+ }
11
+
12
+ p strong {
13
+ color: black;
14
+ }
15
+
16
+ h1, h2, h3, h4, h5, h6 {
17
+ color: #eee;
18
+ margin-top: 2em;
19
+ margin-bottom: 1em;
20
+ text-shadow: 0px 1px 4px rgba(0, 0, 0, 0.7);
21
+ }
22
+
23
+ img {
24
+ border: none;
25
+ }
26
+
27
+ a {
28
+ color: #33a;
29
+ }
30
+
31
+ a:hover {
32
+ color: #55c;
33
+ }
34
+
35
+ p, dl, h3 {
36
+ margin: 1em;
37
+ }
38
+
39
+ h3 {
40
+ border-bottom: 1px solid #ccf;
41
+ }
42
+
43
+ ul {
44
+ margin-bottom: 1em;
45
+ }
46
+
47
+ h3, h4, h5, h6 {
48
+ font-weight: normal;
49
+ }
50
+
51
+ body.front h1 {
52
+ font-weight: normal;
53
+ font-size: 60pt;
54
+ color: white;
55
+ text-shadow:
56
+ 0 1px 0 #ccc,
57
+ 0 2px 0 #c9c9c9,
58
+ 0 3px 0 #bbb,
59
+ 0 4px 0 #b9b9b9,
60
+ 0 5px 0 #aaa,
61
+ 0 6px 1px rgba(0,0,0,.1),
62
+ 0 0 5px rgba(0,0,0,.1),
63
+ 0 1px 3px rgba(0,0,0,.3),
64
+ 0 3px 5px rgba(0,0,0,.2),
65
+ 0 5px 10px rgba(0,0,0,.25),
66
+ 0 10px 10px rgba(0,0,0,.2),
67
+ 0 20px 20px rgba(0,0,0,.15);
68
+
69
+ text-align: center;
70
+ }
@@ -0,0 +1,17 @@
1
+ <page class="front">
2
+ <heading>Welcome to Utopia</heading>
3
+
4
+ <p><strong>Utopia is designed to simplify web development.</strong> Utopia is a fully featured stack for both content-heavy sites and dynamic web applications.</p>
5
+
6
+ <h2>Server Side Tag Based Markup</h2>
7
+
8
+ <p>Server side tags reduce the amount of duplicate view code especially for content-heavy sites.</p>
9
+
10
+ <h2>Recursive Controller Layer</h2>
11
+
12
+ <p>Nested controllers make access control a breeze.</p>
13
+
14
+ <h2>Standards Based Localization</h2>
15
+
16
+ <p>Automatically sniff the user's desired language and provide content in the correct language.</p>
17
+ </page>
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ # Copyright, 2015, 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 '../spec_helper'
24
+
25
+ require 'utopia/content/link'
26
+
27
+ module Utopia::Content::LinkSpec
28
+ describe Utopia::Content::Link.new(:file, "/foo/bar/baz") do
29
+ it "should link should have full path" do
30
+ expect(subject.name).to be == "baz"
31
+ expect(subject.path).to be == Utopia::Path.create("/foo/bar/baz")
32
+ end
33
+ end
34
+
35
+ describe Utopia::Content::Link.new(:directory, "/foo/bar/index") do
36
+ it "should link should have full path" do
37
+ expect(subject.name).to be == "bar"
38
+ expect(subject.path).to be == Utopia::Path.create("/foo/bar/index")
39
+ end
40
+ end
41
+
42
+ describe Utopia::Content::Link.new(:virtual, "bob") do
43
+ it "should link should have full path" do
44
+ expect(subject.name).to be == "bob"
45
+ expect(subject.path).to be == nil
46
+ end
47
+ end
48
+
49
+ describe Utopia::Content::Links do
50
+ it "should give a list of links" do
51
+ links = Utopia::Content::Links.index(File.expand_path("../links", __FILE__), Utopia::Path.create("/"))
52
+
53
+ expect(links.size).to be == 3
54
+
55
+ expect(links[0].kind).to be == :virtual
56
+ expect(links[0].href).to be == nil
57
+
58
+ expect(links[1].title).to be == "Welcome"
59
+ expect(links[1].to_href).to be == '<a class="link" href="/welcome">Welcome</a>'
60
+ expect(links[1].kind).to be == :file
61
+ expect(links[1].href).to be == "/welcome"
62
+ expect(links[1].name).to be == 'welcome'
63
+
64
+ expect(links[2].title).to be == 'Foo Bar'
65
+ expect(links[2].kind).to be == :directory
66
+ expect(links[2].href).to be == "/foo/index"
67
+ expect(links[2].name).to be == 'foo'
68
+
69
+ expect(links[1]).to be_eql links[1]
70
+ expect(links[0]).to_not be_eql links[1]
71
+ end
72
+
73
+ it "should filter links by name" do
74
+ links = Utopia::Content::Links.index(File.expand_path("../links", __FILE__), Utopia::Path.create("/"), name: /foo/)
75
+
76
+ expect(links.size).to be == 1
77
+ end
78
+
79
+ it "should select localized links" do
80
+ root = File.expand_path("../links", __FILE__)
81
+
82
+ # Select both test links
83
+ links = Utopia::Content::Links.index(root, Utopia::Path.create("/foo"))
84
+ expect(links.size).to be == 2
85
+
86
+ links = Utopia::Content::Links.index(root, Utopia::Path.create("/foo"), variant: 'en')
87
+ expect(links.size).to be == 1
88
+ end
89
+
90
+ it "should read correct link order for en" do
91
+ root = File.expand_path("../localized", __FILE__)
92
+
93
+ # Select both test links
94
+ links = Utopia::Content::Links.index(root, Utopia::Path.create("/"), variant: 'en')
95
+
96
+ expect(links.collect(&:title)).to be == ['One', 'Two', 'Three', 'Four', 'Five']
97
+ end
98
+
99
+ it "should read correct link order for zh" do
100
+ root = File.expand_path("../localized", __FILE__)
101
+
102
+ # Select both test links
103
+ links = Utopia::Content::Links.index(root, Utopia::Path.create("/"), variant: 'zh')
104
+
105
+ expect(links.collect(&:title)).to be == ['One', 'Two', 'Three', '四']
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,2 @@
1
+ index:
2
+ title: "Foo Bar"
@@ -0,0 +1,9 @@
1
+ welcome:
2
+ order: 1
3
+ title: "Welcome"
4
+ uri: "/welcome"
5
+ index:
6
+ order: 0
7
+ # This metadata also gets merged with foo/links.yml#index
8
+ foo:
9
+ order: 2