solutus 0.1.3 → 0.1.4

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: ae52f904903e09196391fcb54016663146fb2a5d5684a1c108b4d49c5d6dd89b
4
- data.tar.gz: e130edaeb9cedfef9f7514d70cd20df83575da31a1c936dde187298321085c30
3
+ metadata.gz: 435bfbba6ee0bbf0d94cc46048475f2c97392b37444912473d03c691c41b88e4
4
+ data.tar.gz: 60d55368ad0c6785c53156990c1dc5924a50d42c8bda559167c51689ad4d2052
5
5
  SHA512:
6
- metadata.gz: c4eb0309c57ac9974e34df6ab2eadce3e26d9950845010537575dde21456117963ad1440cc622a7e648d3dc8f35299d34b39f1ee692280f6ab6e85e9ca3749b7
7
- data.tar.gz: 42018df96fbc29c1a8c57fcd404be2f979f4cf21876cdc96de787772ea684cbb41684fa21f07cf3548f4bfab032d90242347b141f22c87d0cd9c5bf1a12b7405
6
+ metadata.gz: 7024ced5ab758fcbd133472a0a1a238563b9d5b11d91aee0588342326566f11d43085a1de9791f34c4c711bfeb64d402bccb592c1de2baab7802d8ebb507dba7
7
+ data.tar.gz: 6fc781fde575954a42defbffc30019ca43e4ab74485147bfc43c5930b057ed33072b52ca708a6bc3ef169801a92163c7fc8c52938697fa224f942102fb192307
data/lib/solutus.rb CHANGED
@@ -24,13 +24,13 @@ class Solutus
24
24
  SITE_PAGES_PATH = File.join("pages", "site-pages")
25
25
  POSTS_PATH = File.join("pages", "posts")
26
26
  BLOG_DATE_FORMAT = "%b %e, %Y"
27
- BLOG_DATE_DATA = "%Y-%m-%e %I:%M:%S"
27
+ BLOG_DATE_DATA = "%Y-%m-%d %I:%M:%S"
28
28
  SETTINGS_FILE = "settings.yml"
29
29
  CACHE = ".solutus-cache"
30
30
  PASSWORD_FILE = "password.txt"
31
31
  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
32
 
33
- VERSION = '0.1.3'
33
+ VERSION = '0.1.4'
34
34
 
35
35
  @@blog_urls = Hash.new
36
36
  @@page_urls = Array.new
@@ -186,6 +186,26 @@ class Solutus
186
186
  "saved post @ #{path}"
187
187
  end
188
188
 
189
+ get "/editfile" do
190
+ if !session[:verified]
191
+ return render_login("You were logged out.")
192
+ end
193
+ path = params['path']
194
+ render_edit_file(path)
195
+ end
196
+
197
+ post "/savefile" do
198
+ if !session[:verified]
199
+ return 'error'
200
+ end
201
+ path = params['path']
202
+ content = params['content']
203
+ f = File.open(path, 'w')
204
+ f.write(content)
205
+ f.close
206
+ 'saved'
207
+ end
208
+
189
209
  post "/publish" do
190
210
  if !session[:verified]
191
211
  return "error"
@@ -212,7 +232,16 @@ class Solutus
212
232
  else
213
233
  send_404
214
234
  end
215
- end
235
+ end
236
+
237
+ def render_edit_file(path)
238
+ #TODO: do smth diff for YML files...
239
+ ServerStache.template = File.read(File.join(path_to_resources, "editFile.html"))
240
+ result = ServerStache.new
241
+ result[:content] = File.read(path)
242
+ result[:path] = path
243
+ result.render
244
+ end
216
245
 
217
246
  def send_404
218
247
  send_file File.join(path_to_resources, "404.html")
@@ -307,6 +336,8 @@ class Solutus
307
336
  result[:blogs] = blog_select
308
337
  result[:pages] = page_select
309
338
  result[:css] = CSS
339
+ result[:files] = render_files
340
+ result[:version] = VERSION
310
341
  result.render
311
342
  end
312
343
 
@@ -321,6 +352,24 @@ class Solutus
321
352
  result
322
353
  end
323
354
 
355
+ def render_files
356
+ result = "<select name=\"path\">\n"
357
+ dirs = [".", "static/css", "templates", "pages/site-pages"]
358
+ dirs.each do |dir|
359
+ result += "<optgroup label='#{dir}'>"
360
+ files = Dir.entries(dir).select {|f| !File.directory? f}
361
+ files.each do |filename|
362
+ if !['password.txt', '.gitignore'].include?(filename)
363
+ path = File.join(dir, filename)
364
+ result += "<option value=\"#{path}\">#{filename}</option>\n"
365
+ end
366
+ end
367
+ result += "</optgroup>"
368
+ end
369
+ result += "</select>"
370
+ result
371
+ end
372
+
324
373
  def blog_select
325
374
  result = "<select name=\"post-path\">\n"
326
375
  Solutus.blog_urls.each do |yr, arr|
@@ -781,6 +830,7 @@ stylesheets: |
781
830
  scripts: |
782
831
  <script></script>
783
832
  recents-count: 3
833
+ advanced: false
784
834
  HERE
785
835
 
786
836
  styles_file = <<HERE
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <title>Editing {{path}}</title>
4
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/codemirror.js"></script>
5
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/codemirror.css">
6
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/mode/htmlmixed/htmlmixed.js"></script>
7
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/theme/lesser-dark.css">
8
+ <style type="text/css">
9
+
10
+ </style>
11
+ {{{stylesheets}}}
12
+ </head>
13
+
14
+ <body>
15
+ <h1>Editing {{path}} (<span id='status'></span>)</h1>
16
+ <a href='/edit'>Back</a>
17
+ <button id='solutus-save-button'>Save</button>
18
+ <textarea id='editor' style='height: 100%;'>{{{content}}}</textarea>
19
+ <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
20
+ <script>
21
+ var myCodeMirror = CodeMirror.fromTextArea(document.getElementById('editor'), {
22
+ lineNumbers: true,
23
+ styleActiveLine: true,
24
+ matchBrackets: true,
25
+ theme: 'lesser-dark'
26
+ });
27
+ myCodeMirror.setSize(null, 600)
28
+
29
+ function updateStatus(status) {
30
+ $("#status").html(status);
31
+ }
32
+
33
+ function save() {
34
+ updateStatus("Saving...")
35
+ $.post("/savefile", {
36
+ "path": "{{path}}",
37
+ "content": myCodeMirror.getValue()
38
+ }, function(response) {
39
+ console.log(response);
40
+ updateStatus("Saved.");
41
+ });
42
+ }
43
+
44
+ $("#solutus-save-button").click(save);
45
+ $(document).keydown(function() {
46
+ updateStatus("Unsaved changes.")
47
+ })
48
+
49
+ updateStatus("Saved.");
50
+ </script>
51
+ </body>
52
+ </html>
data/resources/index.html CHANGED
@@ -8,9 +8,24 @@
8
8
  </head>
9
9
 
10
10
  <body>
11
- <h1>Editing {{name}}</h1>
12
- <p>[<a href="/">View Site</a>]</p>
11
+ <h1>{{name}} Admin</h1>
12
+ {{^advanced}}
13
+ <p>[<a href="/">View Unpublished Site</a>]</p>
14
+ {{/advanced}}
13
15
  <p>[<a href="http://{{domain}}">View Public Site @ {{domain}}</a>]</p>
16
+ {{#advanced}}
17
+ You are in advanced mode.
18
+ <p>
19
+ <form method="get" action="/editfile">
20
+ <fieldset>
21
+ <legend>Edit File</legend>
22
+ {{{files}}}
23
+ <p><button type="submit">Edit file</button></fieldset></p>
24
+ </fieldset>
25
+ </form>
26
+ </p>
27
+ {{/advanced}}
28
+ {{^advanced}}
14
29
  <p>
15
30
  <form method="get" action="/editpage">
16
31
  <fieldset>
@@ -20,6 +35,7 @@
20
35
  </fieldset>
21
36
  </form>
22
37
  </p>
38
+ {{/advanced}}
23
39
  <p>
24
40
  <form method="post" action="/newpost">
25
41
  <fieldset>
@@ -38,13 +54,15 @@
38
54
  </fieldset>
39
55
  </form>
40
56
  </p>
57
+ {{^advanced}}
41
58
  <p>
42
59
  <button type="button" id="publish">Publish to web</button>
43
60
  <span id="status"></span>
44
61
  </p>
62
+ {{/advanced}}
45
63
 
46
64
  <p style="text-align: center;">
47
- <small>Powered by <a href="https://github.com/jeromew21/solutus">Solutus</a></small>
65
+ <small>Powered by <a href="https://github.com/jeromew21/solutus">Solutus</a> {{version}}</small>
48
66
  </p>
49
67
  <script>
50
68
  $("#publish").click(function() {
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Wei
@@ -77,6 +77,7 @@ files:
77
77
  - lib/solutus.rb
78
78
  - resources/404.html
79
79
  - resources/editBlog.html
80
+ - resources/editFile.html
80
81
  - resources/editPage.html
81
82
  - resources/index.html
82
83
  - resources/login.html