Skip to content
This repository
Browse code

Build application finished

  • Loading branch information...
commit f0dbb65121880cbf5818966f256429ffce17f76b 1 parent 68ad595
authored November 14, 2009 hallison committed October 08, 2010
2  bin/postview
@@ -42,8 +42,8 @@ ARGV.options do |arguments|
42 42
       arguments.parse!
43 43
     end
44 44
   rescue => error
45  
-    puts arguments
46 45
     puts error
  46
+    puts arguments
47 47
     exit 1
48 48
   end
49 49
 
66  lib/postview/application/build.rb
@@ -5,8 +5,8 @@ class Postview::Application::Build < Sinatra::Base #:nodoc: all
5 5
 
6 6
   configure do
7 7
     set :root, Postview::ROOT
8  
-    set :public, root.join("lib/postview/application/shared/public")
9  
-    set :views, root.join("lib/postview/application/shared/views")
  8
+    set :public, root.join("lib/postview/application/share")
  9
+    set :views, root.join("lib/postview/application/views")
10 10
 
11 11
     enable :static
12 12
 
@@ -15,14 +15,20 @@ class Postview::Application::Build < Sinatra::Base #:nodoc: all
15 15
   end
16 16
 
17 17
   helpers do
18  
-    attr_reader :page, :settings, :build_path, :errors
  18
+    attr_reader :page, :settings, :postview_path, :errors, :builded
19 19
 
20 20
     def site_settings_valid?
21 21
       site_domain_errors
22 22
       site_email_errors
23 23
       site_author_erros
24 24
       site_password_errors
25  
-      errors.values.compact.empty?
  25
+      no_errors?
  26
+    end
  27
+
  28
+    def no_errors?
  29
+      ATTRIBUTES_REQUIRED.map do |invalid|
  30
+        errors.send(invalid)
  31
+      end.compact.empty?
26 32
     end
27 33
 
28 34
   end
@@ -36,28 +42,26 @@ def site_settings_valid?
36 42
 
37 43
   # Show all information for site.
38 44
   get root_path do
39  
-    page.title = "Settings"
40  
-    erb :setup
  45
+    page.title = "Build blog settings"
  46
+    erb :build
41 47
   end
42 48
 
43 49
   post build_path do
44  
-    page.title = "Build "
45 50
     if site_settings_valid?
46 51
       build!
47  
-      page.title += "successfuly"
48  
-      erb :build
49  
-    else
50  
-      page.title += "failure"
51  
-      erb :setup
  52
+      page.title = "Build successfully"
52 53
     end
  54
+    erb :build
53 55
   end
54 56
 
55 57
 private
56 58
 
  59
+  ATTRIBUTES_REQUIRED =  [ :postview_path, :site_domain, :site_author, :site_email, :password ]
57 60
   REGEX_DOMAIN = /((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/
58 61
   REGEX_EMAIL  = /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@#{REGEX_DOMAIN}/
59 62
 
60 63
   def settings_initialize
  64
+    @builded = false
61 65
     @settings = Postview::Settings.new(settings_params)
62 66
     @settings.site[:token] = Postview::Site.tokenize(@settings.site[:author], params[:password], @settings.site[:domain])
63 67
   end
@@ -69,40 +73,37 @@ def settings_params
69 73
   end
70 74
 
71 75
   def page_initialize
72  
-    @page ||= OpenStruct.new(:name => "Build", :title => "", :keywords => "")
  76
+    @page ||= OpenStruct.new(:title => "", :keywords => "")
73 77
   end
74 78
 
75  
-  # All fields required
  79
+  # Fields required
76 80
   def errors_initialize
77  
-    @errors = [ :domain, :author, :email, :password ].inject({}) do |hash, attribute|
78  
-      hash[:attribute] = nil
79  
-      hash
80  
-    end
  81
+    @errors = Struct.new(*ATTRIBUTES_REQUIRED).new
81 82
   end
82 83
 
83 84
   def build_path_initialize
84  
-    @build_path = params[:build_path] || Postview.path
  85
+    @postview_path = params[:postview_path] || Postview.path
85 86
   end
86 87
 
87 88
   def site_domain_errors
88 89
     return unless params[:site]
89  
-    errors[:domain] = "Domain is required" if params[:site][:domain].to_s.empty?
90  
-    errors[:domain] = "Domain must be an address" unless params[:site][:domain].match(REGEX_DOMAIN)
  90
+    errors.site_domain = "Domain is required" if params[:site][:domain].to_s.empty?
  91
+    errors.site_domain = "Domain must be an address" unless params[:site][:domain].match(REGEX_DOMAIN)
91 92
   end
92 93
 
93 94
   def site_email_errors
94 95
     return unless params[:site]
95  
-    errors[:email] = "Email is required" if params[:site][:email].to_s.empty?
96  
-    errors[:email] = "Email must be an address" unless params[:site][:email].to_s.match(REGEX_EMAIL)
  96
+    errors.site_email = "Email is required" if params[:site][:email].to_s.empty?
  97
+    errors.site_email = "Email must be an address" unless params[:site][:email].to_s.match(REGEX_EMAIL)
97 98
   end
98 99
 
99 100
   def site_author_erros
100 101
     return unless params[:site]
101  
-    errors[:author] = "Author name is required" if params[:site][:author].to_s.empty?
  102
+    errors.site_author = "Author name is required" if params[:site][:author].to_s.empty?
102 103
   end
103 104
 
104 105
   def site_password_errors
105  
-    errors[:password] = "Password is required" if params[:password].to_s.empty?
  106
+    errors.password = "Password is required" if params[:password].to_s.empty?
106 107
   end
107 108
 
108 109
   def settings_yaml
@@ -110,11 +111,16 @@ def settings_yaml
110 111
   end
111 112
 
112 113
   def build!
113  
-    ARGV.clear
114  
-    require 'ruby-debug'
115  
-    debugger
116  
-    ARGV << "#{build_path}" << "--yaml" << settings_yaml
117  
-    Postview::CLI.run :create, ARGV
  114
+    begin
  115
+      ARGV.clear
  116
+      ARGV << "#{postview_path}" << "--yaml" << settings_yaml
  117
+      Postview::CLI.run :create, ARGV
  118
+      @builded = true
  119
+    rescue RuntimeError => error
  120
+      page.title = "Build failure"
  121
+      errors.postview_path = error.to_s
  122
+      throw(:halt, [401, erb(:build)])
  123
+    end
118 124
   end
119 125
 
120 126
 end # class Postview::Application::Build
BIN  lib/postview/application/share/images/gradient-bottom-1x24.png
BIN  lib/postview/application/share/images/gradient-top-1x24.png
BIN  lib/postview/application/share/images/postview-icon.png
BIN  lib/postview/application/share/images/postview-logo.png
115  ...pplication/shared/public/stylesheets/postview.css → ...stview/application/share/stylesheets/postview.css
@@ -12,7 +12,7 @@ body {
12 12
 }
13 13
 
14 14
 fieldset {
15  
-  margin: 8pt 4pt;
  15
+  margin: 4px 0;
16 16
   padding: 4pt;
17 17
   -moz-border-radius: 4px;
18 18
   -webkit-border-radius: 4px;
@@ -20,14 +20,14 @@ fieldset {
20 20
 }
21 21
 
22 22
 fieldset legend {
23  
-  padding: 4pt;
24  
-  font-size: 10pt;
  23
+  padding: 4px;
  24
+  font-size: 14px;
25 25
 }
26 26
 
27 27
 label {
28 28
   margin: 2px;
29  
-  font-size: 8pt;
30  
-  text-shadow: 0px 0px 2px #777;
  29
+  font-size: 12px;
  30
+  text-shadow: 0px 0px 1px #777;
31 31
 }
32 32
 
33 33
 a {
@@ -35,6 +35,10 @@ a {
35 35
   text-decoration: none;
36 36
 }
37 37
 
  38
+img {
  39
+  border: none;
  40
+}
  41
+
38 42
 .field {
39 43
   margin: 2px 4px;
40 44
 }
@@ -61,18 +65,9 @@ a {
61 65
 }
62 66
 
63 67
 .field.error input {
64  
-  -moz-box-shadow: inset 0 0 4px #E33;
65  
-  -webkit-box-shadow: inset 0 0 4px #E33;
66  
-}
67  
-
68  
-.field.large input {
69  
-  display: block;
70  
-}
71  
-
72  
-.commandset {
73  
-  -moz-border-radius: 4px;
74  
-  -webkit-border-radius: 4px;
75  
-  border: 1px solid #AAA;
  68
+  -moz-box-shadow: 0 0 4px #E03030;
  69
+  -webkit-box-shadow: 0 0 4px #E03030;
  70
+  border-color: #E03030;
76 71
 }
77 72
 
78 73
 .command {
@@ -84,86 +79,82 @@ a {
84 79
   text-shadow: 0px 0px 2px #FFF;
85 80
   -moz-border-radius: 4px;
86 81
   -webkit-border-radius: 4px;
87  
-  border: 1px solid #777;
  82
+  border: 1px solid #444;
88 83
   -moz-box-shadow: 0 0 2px #000;
89 84
   -webkit-box-shadow: 0 0 2px #000;
90  
-  background: #E0E0E0 url(../images/gradient-1x16bs.png) repeat-x bottom left;
  85
+  background: #E0E0E0 url(../images/gradient-bottom-1x24.png) repeat-x bottom left;
91 86
 }
92 87
 
93 88
 .command:hover {
94 89
   color: #FFF;
95 90
   text-shadow: 0px 0px 2px #000;
96  
-  border: 1px solid #000;
97  
-  background: #A7A7A7 url(../images/gradient-1x16bs.png) repeat-x bottom left;
  91
+  border-color: #000;
  92
+  background-color: #A7A7A7;
98 93
 }
99 94
 
100 95
 #layout {
101 96
   display: block;
102 97
   clear: both;
103  
-  width: 100%;
104  
-/*
  98
+  width: 780px;
  99
+  margin-top: 32px;
105 100
   margin-left: auto;
106 101
   margin-right: auto;
107  
-  -moz-border-radius: 8px;
108  
-  -webkit-border-radius: 8px;
109  
-  background-color: #DADAEB;
110  
-  border: 8px solid #5C5C9C;
111  
-  -moz-box-shadow: 0 0 6px #000;
112  
-  -webkit-box-shadow: 0 0 6px #000;/**/
  102
+  padding: 6px;
  103
+  -moz-border-radius: 6px;
  104
+  -webkit-border-radius: 6px;
  105
+  -moz-box-shadow: 0 0 16px #000;
  106
+  -webkit-box-shadow: 0 0 16px #000;
  107
+  background-color: #F0F0FF;
  108
+}
  109
+
  110
+#logo {
  111
+}
  112
+
  113
+#title, #subtitle {
  114
+  text-shadow: 2px 0 1px #7F7F7F;
  115
+}
  116
+
  117
+#subtitle {
  118
+  font-size: 10pt;
113 119
 }
114 120
 
115 121
 #header, #content, #footer {
116  
-  margin: 4pt;
117 122
   padding: 4pt;;
118  
-  background-color: #FFF;
119 123
   position: relative;
120 124
 }
121 125
 
122 126
 #header {
123  
-  height: 128px;
  127
+  color: #3F3F3F;
  128
+  border-bottom: 1px solid #7F7F7F;
124 129
 }
125 130
 
126  
-#header, #footer {
127  
-  float: left;
128  
-  width: inherit;
129  
-  margin: 0 0 4pt;
130  
-  padding: 0;
131  
-  color: #FFF;
132  
-  background-color: #1F3366;
133  
-  -moz-box-shadow: 0 0 14pt #000;
134  
-  -webkit-box-shadow: 0 0 14pt #000;
  131
+#footer {
  132
+  border-top: 1px solid #7F7F7F;
135 133
 }
136 134
 
137  
-#content {
  135
+#header, #footer {
  136
+  margin-left: auto;
  137
+  margin-right: auto;
  138
+  padding: 0;
138 139
 }
139 140
 
140 141
 #footer {
141  
-  margin: 4pt 0pt 0pt;
  142
+  margin-bottom: 0;
142 143
   text-align: center;
  144
+  -moz-border-radius: 4px 4px 0 0;
  145
+  -webkit-border-radius: 4px 4px 0 0;
143 146
 }
144 147
 
145  
-#header #version {
146  
-  float: right;
147  
-  font-size: 10pt;
148  
-}
149  
-
150  
-#header * {
151  
-  margin: 0;
152  
-  padding: 0;
153  
-  font-family: serif;
  148
+#header>*, #footer>* {
  149
+  margin: 4px;
  150
+  padding: 4px;
154 151
 }
155 152
 
156 153
 #content {
157 154
   display: block;
158 155
   clear: both;
159  
-  position: relative;
160  
-  top: -60pt;
161  
-  width: 600pt;
162  
-  margin-left: auto;
163  
-  margin-right: auto;
164  
-  background-color: #FFF;
165  
-  border: 8px solid #5C6E9A;
166  
-  -moz-box-shadow: 0 0 14pt #000;
167  
-  -webkit-box-shadow: 0 0 14pt #000;
168  
-  background: #FFF url(../images/gradient-1x256ts.png) repeat-x top left;
  156
+}
  157
+
  158
+#postview_path {
  159
+  width: 732px;
169 160
 }
0  ...view/application/shared/public/stylesheets/wappit → lib/postview/application/share/stylesheets/wappit
File renamed without changes
2  lib/postview/application/shared/views/build.erb
... ...
@@ -1,2 +0,0 @@
1  
-<%=page.title%>
2  
-builded
31  lib/postview/application/shared/views/setup.erb → lib/postview/application/views/build.erb
... ...
@@ -1,6 +1,4 @@
1  
-<h2><%=page.title%></h2>
2  
-
3  
-<%unless site_settings_valid? %>
  1
+<%unless no_errors? %>
4 2
 <p>
5 3
   Please, check all attributes and try again.
6 4
 </p>
@@ -10,11 +8,18 @@
10 8
   <li><%=error%></li>
11 9
 <%end%>
12 10
 </ul>
13  
-<%else%>
  11
+<%end%>
  12
+
  13
+<%unless builded%>
  14
+<p>
  15
+  Welcome to <%=Postview.version_summary%>.
  16
+</p>  
  17
+
14 18
 <p>
15  
-  The next steps will help you choose the values of the settings for your new blog.
  19
+  Thanks for use this software application. Please, input
  20
+  all settings for build a new blog. Remember:
  21
+  <b>The directory path must not exist. Will created automatically.</b>
16 22
 </p>
17  
-<%end%>
18 23
 
19 24
 <form action="<%=path_to :build%>" method="post">
20 25
 
@@ -25,8 +30,8 @@
25 30
     <div>
26 31
 
27 32
       <div class="field large">
28  
-        <label for="build_path">Path</label>
29  
-        <input type="text" id="build_path" name="build_path" value="<%=build_path%>" class="text"/>
  33
+        <label for="postview_path">Postview path</label>
  34
+        <input type="text" id="postview_path" name="postview_path" value="<%=postview_path%>" class="text" size="60"/>
30 35
       </div>
31 36
 
32 37
     </div>
@@ -53,7 +58,7 @@
53 58
 
54 59
     <div>
55 60
 
56  
-      <div class="field <%=:error if errors[:domain]%>" title="<%=errors[:domain]%>">
  61
+      <div class="field <%=:error if errors.site_domain%>" title="<%=errors.site_domain%>">
57 62
         <label for="site_domain">Domain</label>
58 63
         <input type="text" id="site_domain" name="site[domain]" value="<%=settings.site[:domain]%>" class="text"/>
59 64
       </div>
@@ -73,17 +78,17 @@
73 78
 
74 79
     <div>
75 80
 
76  
-      <div class="field <%=:error if errors[:author]%>" title="<%=errors[:author]%>">
  81
+      <div class="field <%=:error if errors.site_author%>" title="<%=errors.site_author%>">
77 82
         <label for="site_author">Name</label>
78 83
         <input type="text" id="site_author" name="site[author]" value="<%=settings.site[:author]%>" class="text"/>
79 84
       </div>
80 85
 
81  
-      <div class="field <%=:error if errors[:email]%>" title="<%=errors[:email]%>">
  86
+      <div class="field <%=:error if errors.site_email%>" title="<%=errors.site_email%>">
82 87
         <label for="site_email">Email</label>
83 88
         <input type="text" id="site_email" name="site[email]" value="<%=settings.site[:email]%>" class="text"/>
84 89
       </div>
85 90
 
86  
-      <div class="field <%=:error if errors[:password]%>" title="<%=errors[:password]%>">
  91
+      <div class="field <%=:error if errors.password%>" title="<%=errors.password%>">
87 92
         <label for="password">Password</label>
88 93
         <input type="password" id="password" name="password" value="" class="text"/>
89 94
       </div>
@@ -130,4 +135,4 @@
130 135
   </fieldset>
131 136
 
132 137
 </form>
133  
-
  138
+<%end%>
14  lib/postview/application/shared/views/layout.erb → lib/postview/application/views/layout.erb
@@ -8,7 +8,7 @@
8 8
   <meta name="generator" content="<%=Postview::version_summary%>" />
9 9
   <meta name="description" content="<%=Postview::about_info.summary%>" />
10 10
   <meta name="keywords" content="<%=page.keywords%>" />
11  
-  <link rel="shortcut icon" href="<%=path_to :images, "favicon.ico"%>" />
  11
+  <link rel="shortcut icon" href="<%=path_to :images, "postview-icon.png"%>" />
12 12
   <link rel="stylesheet" type="text/css" href="<%=path_to :stylesheets, "postview.css"%>" />
13 13
 
14 14
 </head>
@@ -19,14 +19,14 @@
19 19
 
20 20
 <div id="header">
21 21
 
22  
-  <div id="logo">
23  
-    <a href="<%=path_to :root%>" title="Postview" class="column"><img src="<%=path_to "/images/logos/postview.png"%>" alt="Postview"/></a>
  22
+  <div>
  23
+    <h1 id="logo">
  24
+      <a href="<%=path_to :root%>" title="Postview"><img src="<%=path_to "/images/postview-logo.png"%>" alt="Postview"/></a>
  25
+    </h1>
  26
+    <h1 id="title"><%=page.title%></h1>
  27
+    <h2 id="subtitle">v<%=Postview::version_tag%></h2>
24 28
   </div>
25 29
 
26  
-  <h1 id="title" class="column"><%=Postview::name%> - <%=page.name%></h1>
27  
-
28  
-  <h2 id="version" class="column">v<%=Postview::version_tag%></h2>
29  
-
30 30
 </div><!-- header -->
31 31
 
32 32
 <div id="content">
12  test/application_build_test.rb
@@ -9,6 +9,13 @@ class ApplicationBuildTest < Test::Unit::TestCase
9 9
 
10 10
   include Rack::Test::Methods
11 11
 
  12
+  class Postview::Application::Build
  13
+  private
  14
+    def build!
  15
+      erb "builded"
  16
+    end
  17
+  end
  18
+
12 19
   def setup
13 20
     Postview::path = "test/fixtures/blog"
14 21
   end
@@ -21,10 +28,11 @@ def app
21 28
     @app
22 29
   end
23 30
 
24  
-  should "return all settings and all posts in index" do
  31
+  should "build new blog using defaults" do
25 32
 
26  
-    get app.root_path do |response|
  33
+    post app.build_path, :password => "sekret" do |response|
27 34
       assert response.ok?
  35
+      assert_match "successfully", response.body
28 36
     end
29 37
 
30 38
   end

0 notes on commit f0dbb65

Please sign in to comment.
Something went wrong with that request. Please try again.