utopia 1.9.11 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +3 -2
- data/.gitignore +4 -1
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/.yardopts +2 -0
- data/Gemfile +8 -1
- data/README.md +2 -2
- data/Rakefile +10 -10
- data/benchmarks/call_vs_check.rb +36 -0
- data/benchmarks/const_vs_hash.rb +33 -0
- data/documentation/Gemfile +5 -0
- data/documentation/Guardfile +20 -0
- data/documentation/config.ru +6 -13
- data/documentation/config/puma.rb +20 -0
- data/documentation/pages/_editor.xnode +64 -0
- data/documentation/pages/_heading.xnode +2 -2
- data/documentation/pages/_page.xnode +1 -2
- data/documentation/pages/errors/exception.xnode +3 -3
- data/documentation/pages/errors/file-not-found.xnode +3 -3
- data/documentation/pages/wiki/bower-integration/content.md +1 -1
- data/documentation/pages/wiki/content.md +6 -8
- data/documentation/pages/wiki/controller.rb +3 -3
- data/documentation/pages/wiki/edit.xnode +7 -19
- data/documentation/pages/wiki/middleware/content/content.md +4 -10
- data/documentation/pages/wiki/{controller → middleware/controller}/actions/content.md +0 -0
- data/documentation/pages/wiki/{controller → middleware/controller}/links.yaml +0 -0
- data/documentation/pages/wiki/{controller → middleware/controller}/rewrite/content.md +3 -3
- data/documentation/pages/wiki/show.xnode +4 -6
- data/documentation/pages/wiki/updating-utopia/content.md +55 -0
- data/documentation/pages/wiki/your-first-page/content.md +5 -3
- data/documentation/public/materials +1 -0
- data/lib/utopia.rb +3 -4
- data/lib/utopia/command.rb +4 -284
- data/lib/utopia/command/server.rb +115 -0
- data/lib/utopia/command/setup.rb +78 -0
- data/lib/utopia/command/site.rb +183 -0
- data/lib/utopia/content.rb +83 -59
- data/lib/utopia/content/{transaction.rb → document.rb} +116 -110
- data/lib/utopia/content/link.rb +7 -2
- data/lib/utopia/content/links.rb +2 -1
- data/lib/utopia/content/markup.rb +7 -2
- data/lib/utopia/{tags/deferred.rb → content/namespace.rb} +25 -6
- data/lib/utopia/content/node.rb +74 -76
- data/lib/utopia/content/response.rb +22 -3
- data/lib/utopia/content/tags.rb +66 -0
- data/lib/utopia/controller.rb +10 -18
- data/lib/utopia/controller/actions.rb +10 -0
- data/lib/utopia/controller/base.rb +2 -1
- data/lib/utopia/controller/respond.rb +1 -1
- data/lib/utopia/controller/rewrite.rb +8 -4
- data/lib/utopia/exceptions.rb +1 -0
- data/lib/utopia/exceptions/handler.rb +7 -2
- data/lib/utopia/exceptions/mailer.rb +33 -12
- data/lib/utopia/{tags/node.rb → extensions/array_split.rb} +11 -9
- data/lib/utopia/{tags/environment.rb → extensions/date_comparisons.rb} +24 -14
- data/lib/utopia/http.rb +2 -0
- data/lib/utopia/locale.rb +1 -0
- data/lib/utopia/localization.rb +37 -28
- data/lib/utopia/logger.rb +1 -0
- data/lib/utopia/logger/compact_formatter.rb +1 -0
- data/lib/utopia/middleware.rb +11 -1
- data/lib/utopia/path.rb +1 -0
- data/lib/utopia/path/matcher.rb +14 -2
- data/lib/utopia/redirection.rb +13 -16
- data/lib/utopia/session.rb +14 -6
- data/lib/utopia/setup.rb +3 -1
- data/lib/utopia/static.rb +11 -12
- data/lib/utopia/version.rb +1 -1
- data/setup/server/git/hooks/post-receive +0 -4
- data/setup/site/.gitignore +9 -0
- data/setup/site/.rspec +1 -0
- data/setup/site/Gemfile +4 -0
- data/setup/site/Guardfile +17 -0
- data/setup/site/Rakefile +2 -2
- data/setup/site/config.ru +5 -12
- data/setup/site/pages/_heading.xnode +2 -2
- data/setup/site/pages/_page.xnode +1 -1
- data/setup/site/pages/errors/exception.xnode +3 -3
- data/setup/site/pages/errors/file-not-found.xnode +3 -3
- data/setup/site/pages/welcome/index.xnode +3 -3
- data/setup/site/public/_static/site.css +4 -0
- data/setup/site/spec/spec_helper.rb +29 -0
- data/setup/site/tasks/deploy.rake +13 -0
- data/setup/site/tasks/development.rake +34 -0
- data/setup/site/tasks/environment.rake +17 -0
- data/spec/mock_node.rb +15 -0
- data/spec/spec_helper.rb +29 -0
- data/{lib/utopia/extensions/date.rb → spec/utopia/content/document_spec.rb} +31 -21
- data/spec/utopia/content/markup_spec.rb +2 -2
- data/spec/utopia/content/{tag_spec.rb → namespace_spec.rb} +17 -10
- data/spec/utopia/content/tags_spec.rb +80 -0
- data/spec/utopia/content_spec.rb +1 -1
- data/spec/utopia/content_spec.ru +1 -6
- data/spec/utopia/content_spec/_heading.xnode +1 -1
- data/spec/utopia/content_spec/content/test-partial.xnode +1 -1
- data/spec/utopia/content_spec/index.xnode +1 -1
- data/spec/utopia/controller/middleware_spec.ru +1 -3
- data/spec/utopia/controller/respond_spec.rb +2 -22
- data/spec/utopia/controller/respond_spec.ru +1 -5
- data/spec/utopia/controller/respond_spec/errors/file-not-found.xnode +7 -6
- data/spec/utopia/exceptions/handler_spec.ru +1 -2
- data/spec/utopia/exceptions/mailer_spec.ru +1 -2
- data/spec/utopia/extensions_spec.rb +2 -2
- data/spec/utopia/localization_spec.ru +1 -2
- data/spec/utopia/performance_spec.rb +2 -6
- data/spec/utopia/performance_spec/config.ru +5 -12
- data/spec/utopia/performance_spec/pages/_heading.xnode +2 -2
- data/spec/utopia/performance_spec/pages/_page.xnode +1 -1
- data/spec/utopia/performance_spec/pages/errors/exception.xnode +3 -3
- data/spec/utopia/performance_spec/pages/errors/file-not-found.xnode +3 -3
- data/spec/utopia/performance_spec/pages/welcome/index.xnode +3 -3
- data/spec/utopia/setup_spec.rb +79 -15
- data/utopia.gemspec +3 -3
- metadata +41 -27
- data/.simplecov +0 -9
- data/documentation/pages/welcome/index.xnode +0 -41
- data/lib/utopia/content/tag.rb +0 -90
- data/lib/utopia/extensions/array.rb +0 -29
- data/lib/utopia/tags/override.rb +0 -33
- data/setup/site/.simplecov +0 -9
- data/setup/site/tasks/test.rake +0 -10
- data/setup/site/tasks/utopia.rake +0 -41
- data/spec/utopia/controller/respond_spec/rewrite/controller.rb +0 -12
@@ -8,9 +8,9 @@ on '**' do |request, path|
|
|
8
8
|
@page_file = File.join(BASE_PATH, @page_path, "content.md")
|
9
9
|
|
10
10
|
if last_path_component = @page_path.last
|
11
|
-
@
|
11
|
+
@title = Trenni::Strings::to_title(last_path_component)
|
12
12
|
else
|
13
|
-
@
|
13
|
+
@title = "Wiki"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -18,7 +18,7 @@ def read_contents
|
|
18
18
|
if File.exist? @page_file
|
19
19
|
File.read(@page_file)
|
20
20
|
else
|
21
|
-
"\# #{@
|
21
|
+
"\# #{@title}\n\n" +
|
22
22
|
"This page is empty."
|
23
23
|
end
|
24
24
|
end
|
@@ -1,22 +1,10 @@
|
|
1
|
-
<
|
2
|
-
<?r response.do_not_cache! ?>
|
3
|
-
|
4
|
-
<style type="text/css">
|
5
|
-
|
6
|
-
form textarea {
|
7
|
-
|
8
|
-
}
|
9
|
-
</style>
|
10
|
-
|
11
|
-
<heading>Editing #{self[:page_title].inspect}</heading>
|
1
|
+
<content:editor>
|
12
2
|
<form action="#" method="post">
|
13
|
-
<
|
14
|
-
<
|
15
|
-
<textarea name="content">#{self[:content]}</textarea>
|
16
|
-
</fieldset>
|
17
|
-
|
18
|
-
<fieldset class="footer">
|
3
|
+
<div class="header">
|
4
|
+
<div>Editing #{attributes[:title].inspect}</div>
|
19
5
|
<input type="submit" />
|
20
|
-
</
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<textarea name="content">#{self[:content]}</textarea>
|
21
9
|
</form>
|
22
|
-
</
|
10
|
+
</content:editor>
|
@@ -3,25 +3,19 @@ A tag based content generation system which integrates nicely with HTML5. Suppor
|
|
3
3
|
|
4
4
|
```ruby
|
5
5
|
use Utopia::Content,
|
6
|
-
cache_templates: (RACK_ENV == :production)
|
7
|
-
tags: {
|
8
|
-
'deferred' => Utopia::Tags::Deferred,
|
9
|
-
'override' => Utopia::Tags::Override,
|
10
|
-
'node' => Utopia::Tags::Node,
|
11
|
-
'environment' => Utopia::Tags::Environment.for(RACK_ENV)
|
12
|
-
}
|
6
|
+
cache_templates: (RACK_ENV == :production)
|
13
7
|
```
|
14
8
|
|
15
9
|
A basic template `create.xnode` looks something like:
|
16
10
|
|
17
11
|
```trenni
|
18
|
-
<page>
|
19
|
-
<heading>Create User</heading>
|
12
|
+
<content:page>
|
13
|
+
<content:heading>Create User</content:heading>
|
20
14
|
<form action="#">
|
21
15
|
<input name="name" />
|
22
16
|
<input type="submit" />
|
23
17
|
</form>
|
24
|
-
</page>
|
18
|
+
</content:page>
|
25
19
|
```
|
26
20
|
|
27
21
|
This template would typically be designed with supporting `_page.xnode` and `_heading.xnode` in the same directory or, more typically, somewhere further up the directory hierarchy.
|
File without changes
|
File without changes
|
@@ -35,11 +35,11 @@ end
|
|
35
35
|
In your `post.xnode`, as an example:
|
36
36
|
|
37
37
|
```trenni
|
38
|
-
<page>
|
39
|
-
<heading>Post #{attributes[:permalink][:id]} about #{attributes[:permalink][:title]}</heading>
|
38
|
+
<content:page>
|
39
|
+
<content:heading>Post #{attributes[:permalink][:id]} about #{attributes[:permalink][:title]}</content:heading>
|
40
40
|
|
41
41
|
<p>#{attributes[:post].content}</p>
|
42
|
-
</page>
|
42
|
+
</content:page>
|
43
43
|
```
|
44
44
|
|
45
45
|
Keep in mind, that URLs like `/123-pictures-of-my-cat/edit` will work as expected, and hit the `edit` action of the controller.
|
@@ -1,12 +1,10 @@
|
|
1
|
-
<page>
|
2
|
-
|
3
|
-
|
4
|
-
#{partial 'navigation', path: attributes[:full_path].dirname}
|
1
|
+
<content:page>
|
2
|
+
#{partial 'content:navigation', path: attributes[:full_path].dirname}
|
5
3
|
|
6
4
|
#{MarkupString.raw Kramdown::Document.new(self[:content], input: 'GFM', syntax_highlighter: nil).to_html}
|
7
5
|
|
8
6
|
<footer>
|
9
7
|
Last Modified: #{File.mtime(self[:page_file]) rescue "N/A"} —
|
10
|
-
<a href="edit">Edit</a>
|
8
|
+
<a href="edit">Edit Page</a>
|
11
9
|
</footer>
|
12
|
-
</page>
|
10
|
+
</content:page>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Updating Utopia
|
2
|
+
|
3
|
+
Utopia provides a model for both local development (`utopia site create`) and deployment (`utopia server create`). In addition, Utopia provides a basic upgrade path for existing sites when things within the framework change. These are not always automatic, so below are some recipes for how to update your site.
|
4
|
+
|
5
|
+
## Site Update
|
6
|
+
|
7
|
+
Utopia as a framework introduces changes and versions change according to semantic versioning.
|
8
|
+
|
9
|
+
### Controller Update 1.9.x to 2.0.0
|
10
|
+
|
11
|
+
The controller layer no longer automatically prepends the `Actions` layer. The following program does a best effort attempt to update existing controllers:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
#!/usr/bin/env ruby
|
15
|
+
|
16
|
+
paths = Dir.glob("**/controller.rb")
|
17
|
+
|
18
|
+
paths.each do |path|
|
19
|
+
lines = File.readlines(path)
|
20
|
+
|
21
|
+
prepend_line_index = lines.first(5).find_index{|line| line =~ /prepend/}
|
22
|
+
|
23
|
+
unless prepend_line_index
|
24
|
+
puts "Updating #{path}.."
|
25
|
+
File.open(path, "w") do |file|
|
26
|
+
file.puts "\nprepend Actions"
|
27
|
+
file.write lines.join
|
28
|
+
end
|
29
|
+
else
|
30
|
+
prepend_line = lines[prepend_line_index]
|
31
|
+
|
32
|
+
unless prepend_line =~ /Actions/
|
33
|
+
if lines.any?{|line| line =~ /on/}
|
34
|
+
lines[prepend_line_index] = "#{prepend_line.chomp}, Actions\n"
|
35
|
+
|
36
|
+
puts "Updating #{path}.."
|
37
|
+
File.open(path, "w") do |file|
|
38
|
+
file.write lines.join
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Server Update
|
47
|
+
|
48
|
+
The utopia server git hooks are updated occasionally to improve the deployment process or to handle changes in the underlying process.
|
49
|
+
|
50
|
+
You can run the update process on the server to bring the git hooks up to the latest version.
|
51
|
+
|
52
|
+
```bash
|
53
|
+
$ cd /srv/http/website
|
54
|
+
$ utopia server update
|
55
|
+
```
|
@@ -9,18 +9,20 @@ $ utopia site create
|
|
9
9
|
$ rake server
|
10
10
|
```
|
11
11
|
|
12
|
-
You will now have a basic template site running on http://localhost:9292
|
12
|
+
You will now have a basic template site running on <a href="http://localhost:9292">http://localhost:9292</a>.
|
13
13
|
|
14
14
|
## Welcome Page
|
15
15
|
|
16
16
|
Utopia includes a redirection middleware to redirect all root-level requests to a given URI. The default being `/welcome/index`:
|
17
17
|
|
18
18
|
```ruby
|
19
|
+
# in config.ru
|
20
|
+
|
19
21
|
use Utopia::Redirection::Rewrite,
|
20
22
|
'/' => '/welcome/index'
|
21
23
|
```
|
22
24
|
|
23
|
-
This page includes a basic overview of Utopia. Most of it's standard HTML, except for the outer `<page>` tag. Utopia uses the name `page` to lookup the file-system hierarchy. First, it looks for `/welcome/_page.xnode`, and then it looks for `/_page.xnode` which it finds. This page template includes a tag `<content/>` which is replaced with the inner body of the `<page>` tag. This recursive lookup is the heart of Utopia.
|
25
|
+
This page includes a basic overview of Utopia. Most of it's standard HTML, except for the outer `<content:page>` tag. Utopia uses the name `page` to lookup the file-system hierarchy. First, it looks for `/welcome/_page.xnode`, and then it looks for `/_page.xnode` which it finds. This page template includes a tag `<utopia:content/>` which is replaced with the inner body of the `<content:page>` tag. This recursive lookup is the heart of Utopia.
|
24
26
|
|
25
27
|
## Links
|
26
28
|
|
@@ -33,4 +35,4 @@ You'll notice that there is a file `/links.yaml`. This file contains important m
|
|
33
35
|
```yaml
|
34
36
|
errors:
|
35
37
|
display: false
|
36
|
-
```
|
38
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
documentation/public/../../materials
|
data/lib/utopia.rb
CHANGED
@@ -28,7 +28,6 @@ require_relative 'utopia/redirection'
|
|
28
28
|
require_relative 'utopia/static'
|
29
29
|
require_relative 'utopia/content_length'
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
require_relative 'utopia/tags/override'
|
31
|
+
# Utopia is a web application framework built on top of Rack.
|
32
|
+
module Utopia
|
33
|
+
end
|
data/lib/utopia/command.rb
CHANGED
@@ -20,293 +20,12 @@
|
|
20
20
|
|
21
21
|
require_relative 'version'
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
require 'yaml/store'
|
27
|
-
|
28
|
-
require 'samovar'
|
29
|
-
require 'securerandom'
|
23
|
+
require_relative 'command/site'
|
24
|
+
require_relative 'command/server'
|
30
25
|
|
31
26
|
module Utopia
|
32
27
|
module Command
|
33
|
-
|
34
|
-
# This path must point to utopia/setup in the gem source.
|
35
|
-
BASE = File.expand_path("../../setup", __dir__)
|
36
|
-
|
37
|
-
module Site
|
38
|
-
CONFIGURATION_FILES = ['.bowerrc', 'config.ru', 'config/environment.rb', 'Gemfile', 'Rakefile', 'tasks/utopia.rake', 'tasks/bower.rake', 'tasks/test.rake']
|
39
|
-
|
40
|
-
DIRECTORIES = ["config", "lib", "pages", "public", "tasks"]
|
41
|
-
|
42
|
-
# Removed during upgrade process
|
43
|
-
OLD_DIRECTORIES = ["access_log", "cache", "tmp"]
|
44
|
-
|
45
|
-
ROOT = File.join(BASE, 'site')
|
46
|
-
end
|
47
|
-
|
48
|
-
module Server
|
49
|
-
ROOT = File.join(BASE, 'server')
|
50
|
-
|
51
|
-
def self.environment(root)
|
52
|
-
# Setup config/environment.yaml according to specified options:
|
53
|
-
environment_path = File.join(root, 'config/environment.yaml')
|
54
|
-
FileUtils.mkpath File.dirname(environment_path)
|
55
|
-
|
56
|
-
store = YAML::Store.new(environment_path)
|
57
|
-
|
58
|
-
store.transaction do
|
59
|
-
yield store
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Set some useful defaults for the environment:
|
64
|
-
def self.update_default_environment(root)
|
65
|
-
# Set up some useful defaults for server environment:
|
66
|
-
environment(root) do |store|
|
67
|
-
store['RACK_ENV'] ||= 'production'
|
68
|
-
store['UTOPIA_SESSION_SECRET'] ||= SecureRandom.hex(40)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class Server < Samovar::Command
|
75
|
-
class Create < Samovar::Command
|
76
|
-
self.description = "Create a remote Utopia website suitable for deployment using git."
|
77
|
-
|
78
|
-
def invoke(parent)
|
79
|
-
destination_root = parent.root
|
80
|
-
|
81
|
-
FileUtils.mkdir_p File.join(destination_root, "public")
|
82
|
-
|
83
|
-
Dir.chdir(destination_root) do
|
84
|
-
# Shared allows multiple users to access the site with the same group:
|
85
|
-
system("git", "init", "--shared")
|
86
|
-
system("git", "config", "receive.denyCurrentBranch", "ignore")
|
87
|
-
system("git", "config", "core.worktree", destination_root)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Copy git hooks:
|
91
|
-
system("cp", "-r", File.join(Setup::Server::ROOT, 'git', 'hooks'), File.join(destination_root, '.git'))
|
92
|
-
|
93
|
-
Setup::Server.update_default_environment(destination_root)
|
94
|
-
|
95
|
-
# Print out helpful git remote add message:
|
96
|
-
hostname = `hostname`.chomp
|
97
|
-
puts "Now add the git remote to your local repository:\n\tgit remote add production ssh://#{hostname}#{destination_root}"
|
98
|
-
puts "Then push to it:\n\tgit push --set-upstream production master"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
class Update < Samovar::Command
|
103
|
-
self.description = "Update the git hooks in an existing server repository."
|
104
|
-
|
105
|
-
def invoke(parent)
|
106
|
-
destination_root = parent.root
|
107
|
-
|
108
|
-
Dir.chdir(destination_root) do
|
109
|
-
system("git", "config", "receive.denyCurrentBranch", "ignore")
|
110
|
-
system("git", "config", "core.worktree", destination_root)
|
111
|
-
end
|
112
|
-
|
113
|
-
# Copy git hooks:
|
114
|
-
system("cp", "-r", File.join(Setup::Server::ROOT, 'git', 'hooks'), File.join(destination_root, '.git'))
|
115
|
-
Setup::Server.update_default_environment(destination_root)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
class Environment < Samovar::Command
|
120
|
-
self.description = "Update environment variables in config/environment.yaml"
|
121
|
-
|
122
|
-
many :variables, "A list of environment KEY=VALUE pairs to set."
|
123
|
-
|
124
|
-
def invoke(parent)
|
125
|
-
return if variables.empty?
|
126
|
-
|
127
|
-
destination_root = parent.root
|
128
|
-
|
129
|
-
Setup::Server.environment(destination_root) do |store|
|
130
|
-
variables.each do |variable|
|
131
|
-
key, value = variable.split('=', 2)
|
132
|
-
|
133
|
-
if value
|
134
|
-
puts "ENV[#{key.inspect}] will default to #{value.inspect} unless otherwise specified."
|
135
|
-
store[key] = value
|
136
|
-
else
|
137
|
-
puts "ENV[#{key.inspect}] will be unset unless otherwise specified."
|
138
|
-
store.delete(key)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
self.description = "Manage server deployments."
|
146
|
-
|
147
|
-
nested '<command>',
|
148
|
-
'create' => Create,
|
149
|
-
'update' => Update,
|
150
|
-
'environment' => Environment
|
151
|
-
|
152
|
-
def invoke(parent)
|
153
|
-
@command.invoke(parent)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
class Site < Samovar::Command
|
158
|
-
class Create < Samovar::Command
|
159
|
-
self.description = "Create a new local Utopia website using the default template."
|
160
|
-
# self.example = "utopia --in www.example.com site create"
|
161
|
-
|
162
|
-
def invoke(parent)
|
163
|
-
destination_root = parent.root
|
164
|
-
|
165
|
-
$stderr.puts "Setting up initial site in #{destination_root} for Utopia v#{Utopia::VERSION}..."
|
166
|
-
|
167
|
-
Setup::Site::DIRECTORIES.each do |directory|
|
168
|
-
FileUtils.mkdir_p(File.join(destination_root, directory))
|
169
|
-
end
|
170
|
-
|
171
|
-
Find.find(Setup::Site::ROOT) do |source_path|
|
172
|
-
# What is this doing?
|
173
|
-
destination_path = File.join(destination_root, source_path[Setup::Site::ROOT.size..-1])
|
174
|
-
|
175
|
-
if File.directory?(source_path)
|
176
|
-
FileUtils.mkdir_p(destination_path)
|
177
|
-
else
|
178
|
-
unless File.exist? destination_path
|
179
|
-
FileUtils.copy_entry(source_path, destination_path)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
Setup::Site::CONFIGURATION_FILES.each do |configuration_file|
|
185
|
-
destination_path = File.join(destination_root, configuration_file)
|
186
|
-
|
187
|
-
buffer = File.read(destination_path).gsub('$UTOPIA_VERSION', Utopia::VERSION)
|
188
|
-
|
189
|
-
File.open(destination_path, "w") { |file| file.write(buffer) }
|
190
|
-
end
|
191
|
-
|
192
|
-
Dir.chdir(destination_root) do
|
193
|
-
puts "Setting up site in #{destination_root}..."
|
194
|
-
|
195
|
-
if `which bundle`.strip != ''
|
196
|
-
puts "Generating initial package list with bundle..."
|
197
|
-
system("bundle", "install", "--binstubs")
|
198
|
-
end
|
199
|
-
|
200
|
-
if `which git`.strip == ""
|
201
|
-
$stderr.puts "Now is a good time to learn about git: http://git-scm.com/"
|
202
|
-
elsif !File.exist?('.git')
|
203
|
-
puts "Setting up git repository..."
|
204
|
-
system("git", "init")
|
205
|
-
system("git", "add", ".")
|
206
|
-
system("git", "commit", "-q", "-m", "Initial Utopia v#{Utopia::VERSION} site.")
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
name = `git config user.name || whoami`.chomp
|
211
|
-
|
212
|
-
puts
|
213
|
-
puts " #{name},".ljust(78)
|
214
|
-
puts "Thank you for using Utopia!".center(78)
|
215
|
-
puts "We sincerely hope that Utopia helps to".center(78)
|
216
|
-
puts "make your life easier and more enjoyable.".center(78)
|
217
|
-
puts ""
|
218
|
-
puts "To start the development server, run:".center(78)
|
219
|
-
puts "rake server".center(78)
|
220
|
-
puts ""
|
221
|
-
puts "For extreme productivity, please consult the online documentation".center(78)
|
222
|
-
puts "https://github.com/ioquatix/utopia".center(78)
|
223
|
-
puts " ~ Samuel. ".rjust(78)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
class Update < Samovar::Command
|
228
|
-
self.description = "Upgrade an existing site to use the latest configuration files from the template."
|
229
|
-
|
230
|
-
def move_static!
|
231
|
-
if File.lstat("public/_static").symlink?
|
232
|
-
FileUtils.rm_f "public/_static"
|
233
|
-
end
|
234
|
-
|
235
|
-
if File.directory?("pages/_static") and !File.exist?("public/_static")
|
236
|
-
system("git", "mv", "pages/_static", "public/_static")
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def invoke(parent)
|
241
|
-
destination_root = parent.root
|
242
|
-
branch_name = "utopia-upgrade-#{Utopia::VERSION}"
|
243
|
-
|
244
|
-
$stderr.puts "Upgrading #{destination_root}..."
|
245
|
-
|
246
|
-
Dir.chdir(destination_root) do
|
247
|
-
system('git', 'checkout', '-b', branch_name)
|
248
|
-
end
|
249
|
-
|
250
|
-
Setup::Site::DIRECTORIES.each do |directory|
|
251
|
-
FileUtils.mkdir_p(File.join(destination_root, directory))
|
252
|
-
end
|
253
|
-
|
254
|
-
Setup::Site::OLD_DIRECTORIES.each do |directory|
|
255
|
-
path = File.join(destination_root, directory)
|
256
|
-
$stderr.puts "\tRemoving #{path}..."
|
257
|
-
FileUtils.rm_rf(path)
|
258
|
-
end
|
259
|
-
|
260
|
-
Setup::Site::CONFIGURATION_FILES.each do |configuration_file|
|
261
|
-
source_path = File.join(Setup::Site::ROOT, configuration_file)
|
262
|
-
destination_path = File.join(destination_root, configuration_file)
|
263
|
-
|
264
|
-
$stderr.puts "Updating #{destination_path}..."
|
265
|
-
|
266
|
-
FileUtils.copy_entry(source_path, destination_path)
|
267
|
-
buffer = File.read(destination_path).gsub('$UTOPIA_VERSION', Utopia::VERSION)
|
268
|
-
File.open(destination_path, "w") { |file| file.write(buffer) }
|
269
|
-
end
|
270
|
-
|
271
|
-
begin
|
272
|
-
Dir.chdir(destination_root) do
|
273
|
-
# Stage any files that have been changed or removed:
|
274
|
-
system("git", "add", "-u")
|
275
|
-
|
276
|
-
# Stage any new files that we have explicitly added:
|
277
|
-
system("git", "add", *Setup::Site::CONFIGURATION_FILES)
|
278
|
-
|
279
|
-
move_static!
|
280
|
-
|
281
|
-
# Commit all changes:
|
282
|
-
system("git", "commit", "-m", "Upgrade to utopia #{Utopia::VERSION}.")
|
283
|
-
|
284
|
-
# Checkout master..
|
285
|
-
system("git", "checkout", "master")
|
286
|
-
|
287
|
-
# and merge:
|
288
|
-
system("git", "merge", "--no-commit", "--no-ff", branch_name)
|
289
|
-
end
|
290
|
-
rescue RuntimeError
|
291
|
-
$stderr.puts "** Detected error with upgrade, reverting changes. Some new files may still exist in tree. **"
|
292
|
-
|
293
|
-
system("git", "checkout", "master")
|
294
|
-
system("git", "branch", "-d", branch_name)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
nested '<command>',
|
300
|
-
'create' => Create,
|
301
|
-
'update' => Update
|
302
|
-
|
303
|
-
self.description = "Manage local utopia sites."
|
304
|
-
|
305
|
-
def invoke(parent)
|
306
|
-
@command.invoke(parent)
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
28
|
+
# The top level utopia command.
|
310
29
|
class Top < Samovar::Command
|
311
30
|
self.description = "A website development and deployment framework."
|
312
31
|
|
@@ -320,6 +39,7 @@ module Utopia
|
|
320
39
|
'site' => Site,
|
321
40
|
'server' => Server
|
322
41
|
|
42
|
+
# The root directory for the site.
|
323
43
|
def root
|
324
44
|
File.expand_path(@options.fetch(:root, ''), Dir.getwd)
|
325
45
|
end
|