solutus 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a3716f57a2963942df64c1148bc85dd01613da9673e0f8d70640c9cb2621788
4
- data.tar.gz: 04a880858d6bfa6f414c727a3eaba3ca396a88af3fda2a332d697560b3648e26
3
+ metadata.gz: a4e5dfc711131b2732b3179bb8bc40adac3c9dbf071f5e37e6edb2cb68421d46
4
+ data.tar.gz: 4e00e1d6a9f78530fe55e20f3af15384484f0cad83a0c5b682e7d6d751ef16df
5
5
  SHA512:
6
- metadata.gz: 8dbe8e509ec4522894f3463bf6e9a5664e198f834cba445ff72027091aabe66ffbb717acf0bf75d474f7ab5e1b8eee5e2040f97b18b301fad440db2d3260a507
7
- data.tar.gz: 5f20e6a80b3e0ff8ee837898bc3c48b9088a81ea4d4f99757f0a22edee386c2d05b5b04c94c58e1dc054968e47aafdd2064881b0003706fe6ccafab133c39a94
6
+ metadata.gz: a2a15e30c6b22f8b6b513b1b04497e93e78fad19f1225b8afdaa09a96be541d69c42a2eaa67e7911e2b346d7daa11e8395ed6bf38dea1d6c35d7b3547cafbc72
7
+ data.tar.gz: 11a67bf8b78990bb57c086ef0ca00901305b4edf2976d2abe648babfa4ab3292965c3775545be52ca9c922568ebbc945bfb9e0e4f6d8924b2820a9f1b15fc76a
@@ -7,6 +7,7 @@ require 'json'
7
7
  require 'nokogiri'
8
8
  require 'digest'
9
9
  require "rubygems"
10
+ require 'uri'
10
11
 
11
12
  #TODO: Add support for tags
12
13
  #TODO: Make stress tests
@@ -30,7 +31,7 @@ class Solutus
30
31
  PASSWORD_FILE = "password.txt"
31
32
  DAY_ENDINGS = ["th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "st"]
32
33
 
33
- VERSION = '0.1.9'
34
+ VERSION = '0.2.0'
34
35
 
35
36
  LOG_FILE = 'log'
36
37
 
@@ -58,6 +59,9 @@ class Solutus
58
59
  class Solutus_Server < Sinatra::Base
59
60
  CSS = File.read(File.join(File.dirname(File.expand_path(__FILE__)), '../resources', "style.css"))
60
61
  FILE_EXCLUDES = ['password.txt', '.gitignore', 'nohup.out', 'log']
62
+ UPLOAD_DIR_SUFF = 'i'
63
+ UPLOAD_DIR = File.join(STATIC_PATH, UPLOAD_DIR_SUFF)
64
+
61
65
  enable :sessions
62
66
 
63
67
  set :public_folder, SITE_PATH
@@ -148,6 +152,9 @@ class Solutus
148
152
  end
149
153
 
150
154
  get "/newpage" do
155
+ if !session[:verified]
156
+ return "error"
157
+ end
151
158
  dir = params['dir']
152
159
  filename = params['filename']
153
160
  dir = File.join(SITE_PAGES_PATH, dir)
@@ -155,6 +162,9 @@ class Solutus
155
162
  if !File.directory?(dir)
156
163
  FileUtils.mkdir_p(dir)
157
164
  end
165
+ if file.file?(path)
166
+ return 'error: file already exists'
167
+ end
158
168
  f = File.new(path, 'w')
159
169
  title = 'Page Title'
160
170
  text = <<HERE
@@ -246,6 +256,37 @@ HERE
246
256
  'saved'
247
257
  end
248
258
 
259
+ post "/upload" do
260
+ if !session[:verified]
261
+ return "error"
262
+ end
263
+
264
+ filename = URI.escape(params[:file][:filename])
265
+ file = params[:file][:tempfile]
266
+ dir = params[:dir] #Probably sanitizxe this
267
+
268
+ unless File.directory?(UPLOAD_DIR)
269
+ FileUtils.mkdir_p(UPLOAD_DIR)
270
+ end
271
+
272
+ unless File.directory?(File.join(UPLOAD_DIR, dir))
273
+ FileUtils.mkdir_p(File.join(UPLOAD_DIR, dir))
274
+ end
275
+
276
+ path_to_file = File.join(UPLOAD_DIR, dir, filename)
277
+
278
+ File.open(path_to_file, 'wb') do |f|
279
+ f.write(file.read)
280
+ end
281
+
282
+ Solutus.command("build")
283
+
284
+ link = settings.global_settings['domain'] + "/" + UPLOAD_DIR_SUFF + "/#{dir}/" + filename
285
+ render_local('base.html', {
286
+ "content" => "<h1>Link</h1><strong><a href='http://#{link}'>#{link}</a></strong><p><a href='/edit'>back</a></p>"
287
+ })
288
+ end
289
+
249
290
  post "/publish" do
250
291
  if !session[:verified]
251
292
  return "error"
@@ -402,10 +443,30 @@ HERE
402
443
  result[:pages] = page_select
403
444
  result[:css] = CSS
404
445
  result[:files] = render_files
446
+ result[:file_upload_paths] = render_file_upload_dirs
405
447
  result[:version] = VERSION
406
448
  result.render
407
449
  end
408
450
 
451
+ def render_local(f, data)
452
+ f = File.open(File.join(path_to_resources, f), "r")
453
+ template = ""
454
+ f.each_line do |line|
455
+ template += line
456
+ end
457
+ f.close
458
+ SolutusStache.template = template
459
+ result = SolutusStache.new
460
+ settings.global_settings.each do |key, val|
461
+ result[key.to_sym] = val
462
+ end
463
+ data.each do |key, val|
464
+ result[key.to_sym] = val
465
+ end
466
+ result[:css] = CSS
467
+ result.render
468
+ end
469
+
409
470
  def page_select
410
471
  result = "<select name=\"page-path\">\n"
411
472
  Solutus.page_urls.each do |page|
@@ -441,6 +502,19 @@ HERE
441
502
  result
442
503
  end
443
504
 
505
+ def render_file_upload_dirs
506
+ result = ''
507
+ unless File.directory?(UPLOAD_DIR)
508
+ FileUtils.mkdir_p(UPLOAD_DIR)
509
+ end
510
+ Dir.entries(UPLOAD_DIR).each do |d|
511
+ if (d != '.' && d != '..') && File.directory?(File.join(UPLOAD_DIR, d))
512
+ result += "<option>#{d}</option>"
513
+ end
514
+ end
515
+ result
516
+ end
517
+
444
518
  def blog_select
445
519
  result = "<select name=\"post-path\">\n"
446
520
  Solutus.blog_urls.each do |yr, arr|
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <title>Edit Site</title>
4
+ <style type="text/css">
5
+ {{css}}
6
+ </style>
7
+ <body>
8
+ {{{content}}}
9
+ </body>
10
+ </head>
@@ -20,7 +20,7 @@
20
20
  <fieldset>
21
21
  <legend>Edit File</legend>
22
22
  {{{files}}}
23
- <p><button type="submit">Edit file</button></fieldset></p>
23
+ <p><button type="submit">Edit file</button></p>
24
24
  </fieldset>
25
25
  </form>
26
26
  </p>
@@ -32,10 +32,25 @@
32
32
  Page subdirectory:
33
33
  <select name='dir'>{{{page_paths}}}</select>
34
34
  <p>Page name: <input type='text' name='filename'></p>
35
- <p><button type="submit">Create page</button></fieldset></p>
35
+ <p><button type="submit">Create page</button></p>
36
36
  </fieldset>
37
37
  </form>
38
38
  </p>
39
+
40
+ <p>
41
+ <form method="post" action="/upload" enctype="multipart/form-data">
42
+ <fieldset>
43
+ <legend>Upload File and Get Link</legend>
44
+ <p><input type="file" name="file"></p>
45
+ File subdirectory:
46
+ <input list="fofoo" required name='dir' />
47
+ <datalist id="fofoo">{{{file_upload_paths}}}</datalist>
48
+ <p><button type="submit">Upload file</button></p>
49
+ </fieldset>
50
+ </form>
51
+ </p>
52
+
53
+
39
54
  {{/advanced}}
40
55
  {{^advanced}}
41
56
  <p>
@@ -43,7 +58,7 @@
43
58
  <fieldset>
44
59
  <legend>Edit Page</legend>
45
60
  {{{pages}}}
46
- <p><button type="submit">Edit page</button></fieldset></p>
61
+ <p><button type="submit">Edit page</button></p>
47
62
  </fieldset>
48
63
  </form>
49
64
  </p>
@@ -52,7 +67,7 @@
52
67
  <fieldset>
53
68
  <legend>New Blog Post</legend>
54
69
  <p><label for="post-title">Title:</label> <input type="text" name="post-title"></p>
55
- <p><button type="submit">Create new blog post</button></fieldset></p>
70
+ <p><button type="submit">Create new blog post</button></p>
56
71
  </fieldset>
57
72
  </form>
58
73
  </p>
@@ -61,7 +76,7 @@
61
76
  <fieldset>
62
77
  <legend>Edit Blog Post</legend>
63
78
  {{{blogs}}}
64
- <p><button type="submit">Edit blog post</button></fieldset></p>
79
+ <p><button type="submit">Edit blog post</button></p>
65
80
  </fieldset>
66
81
  </form>
67
82
  </p>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solutus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Wei
@@ -76,6 +76,7 @@ files:
76
76
  - bin/solutus
77
77
  - lib/solutus.rb
78
78
  - resources/404.html
79
+ - resources/base.html
79
80
  - resources/editBlog.html
80
81
  - resources/editFile.html
81
82
  - resources/editPage.html