solutus 0.0.1 → 0.0.2

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: 726e73c608c5ee52e178eb44a2b8c49b4c045c91691931a060fdea8c4d5eb4b0
4
- data.tar.gz: e596ad97cc3e985b693d0836f80a10cd48545457e0aacb668b97599b4ac96d44
3
+ metadata.gz: 49cd8eff79c5ef6ec077eca26f41a41d665388f7a4dcac730a310f1df588cb95
4
+ data.tar.gz: 8f502367c1b27d14040cf2856fab20f365f91b3c05e6b26486a4102a8329e3fc
5
5
  SHA512:
6
- metadata.gz: 740a22d2d1054ff79d0a5458ceeea692e752b49cb7f20ec228592842acb2901464c09ef88e66b34ceecd1d479063be53b3006c7c19af40062900df450acd2de7
7
- data.tar.gz: 5c6844b88e67dec102939d105f369bd65420e096e5af6d543480f594a18b504bc298cc6041f697d26a49c574f281de63b9ae9250fa7e54b3f5da7365d54d8297
6
+ metadata.gz: a1aae2085d6b3ac081bf89db1e3b74a2aba9b72c4616e8b1ab977409f4da952cf0a8d8e3fde3e00946a69ba79f1bfa90639cc9396a8ca746c1bcdd6b1db4bfcb
7
+ data.tar.gz: '09e0f4b38235c12bc62efed2705bbf021ac68428cda126a9e1429daf18becea546c680ea76d769b5e4730f06e006f61b9c585a6d6f4d9e28656abd5b9e8356f3'
@@ -9,11 +9,13 @@ class Solutus
9
9
  BLOG_TEMPLATE = "post"
10
10
  BUILD_PATH = "deploy"
11
11
  SITE_PATH = File.join(BUILD_PATH, "site")
12
+ BLOG_BUILD_PATH = File.join(SITE_PATH, "archive")
12
13
  STATIC_PATH = "static"
13
14
  TEMPLATES_PATH = "templates"
14
15
  SITE_PAGES_PATH = File.join("pages", "site-pages")
15
16
  POSTS_PATH = File.join("pages", "posts")
16
17
  BLOG_DATE_FORMAT = "%b %-d, %Y"
18
+ SETTINGS_FILE = "settings.yml"
17
19
 
18
20
  class Solutus_Server < Sinatra::Base
19
21
  set :public_folder, SITE_PATH
@@ -21,13 +23,24 @@ class Solutus
21
23
  get "/" do
22
24
  send_file File.join(settings.public_folder, 'index.html')
23
25
  end
26
+
27
+ get "/reset" do
28
+ Solutus.command("build")
29
+ redirect "/"
30
+ end
24
31
 
25
32
  get "/edit" do
26
- redirect '/edit/'
33
+ send_file File.join(path_to_resources, "index.html")
27
34
  end
28
-
29
- get "/edit/?" do
30
- "Edit your site!"
35
+
36
+ post "/newpost" do
37
+ Solutus.command("new", "post", params["post-title"])
38
+ Solutus.build
39
+ send_file File.join(path_to_resources, "editBlog.html")
40
+ end
41
+
42
+ def path_to_resources
43
+ File.join(File.dirname(File.expand_path(__FILE__)), '../resources')
31
44
  end
32
45
  end
33
46
 
@@ -79,6 +92,13 @@ class Solutus
79
92
  end
80
93
 
81
94
  def self.build
95
+ yml_text = ""
96
+ f = File.open(SETTINGS_FILE, "r")
97
+ f.each_line do |line|
98
+ yml_text += line
99
+ end
100
+ settings_data = YAML.load(yml_text)
101
+
82
102
  if File.directory?(BUILD_PATH)
83
103
  FileUtils.remove_dir(BUILD_PATH)
84
104
  end
@@ -112,7 +132,7 @@ class Solutus
112
132
  yml_text += line
113
133
  end
114
134
  data = YAML.load(yml_text)
115
- html = render_page(templates, data, false)
135
+ html = render_page(templates, settings_data, data, false)
116
136
  new_path = File.join(SITE_PATH, entry.split(".")[0] + ".html")
117
137
  f = File.new(new_path, "w")
118
138
  puts "Created #{new_path}"
@@ -121,6 +141,7 @@ class Solutus
121
141
  end
122
142
  end
123
143
 
144
+ blog_urls = Hash.new
124
145
  Dir.entries(POSTS_PATH).each do |entry|
125
146
  next if entry == "." || entry == ".."
126
147
  path = File.join(POSTS_PATH, entry)
@@ -136,19 +157,51 @@ class Solutus
136
157
  date = data["date"]
137
158
 
138
159
  puts "Rendering blog post #{entry}"
139
- html = render_page(templates, data, true)
160
+ html = render_page(templates, settings_data, data, true)
161
+
162
+ relative_dir = File.join(date.year.to_s, date.month.to_s, date.day.to_s)
163
+ root_url = File.join("archive", relative_dir, entry.split(".")[0] + ".html")
164
+
165
+ year = date.year.to_s
166
+ if !blog_urls.key?(year)
167
+ blog_urls[year] = Array.new
168
+ end
169
+ blog_urls[year].push({"title" => data["title"], "url" => root_url, "date" => date})
140
170
 
141
- dir_path = File.join(SITE_PATH, date.year.to_s, date.month.to_s, date.day.to_s)
171
+ dir_path = File.join(BLOG_BUILD_PATH, relative_dir)
142
172
  if !File.directory?(dir_path)
143
173
  FileUtils.mkdir_p(dir_path)
144
174
  end
145
- file_path = File.join(dir_path, entry.split(".")[0] + ".html")
175
+ file_path = File.join(SITE_PATH, root_url)
146
176
  puts "Created #{file_path}"
147
177
  f = File.new(file_path, "w")
148
178
  f.write(html)
149
179
  f.close()
150
- end
180
+ end
181
+
151
182
  #TODO: CREATE SOME FCUKIN BLOG NAVIGATION HTML PAGES
183
+ content = ""
184
+ blog_urls.each do |yr, arr|
185
+ sorted = arr.sort_by {|k| k["date"]} .reverse
186
+ content += "<h3>#{yr}</h3>\n<hr>\n"
187
+ content += "<ul>"
188
+ sorted.each do |hash|
189
+ url = hash["url"]
190
+ title = hash["title"]
191
+ pretty_date = hash["date"].strftime("%b %-d")
192
+ content += "<li><a href=\"/#{url}\">#{title}</a> (#{pretty_date})</li>"
193
+ end
194
+ content += "</ul>"
195
+ end
196
+ path = File.join(SITE_PATH, "archive.html")
197
+ data = Hash.new
198
+ data["title"] = "Archive"
199
+ data["content"] = content
200
+ html = render_page(templates, settings_data, data, false)
201
+ f = File.new(path, "w")
202
+ f.write(html)
203
+ f.close
204
+ puts "Created blog archive @ #{path}"
152
205
 
153
206
  end
154
207
 
@@ -193,7 +246,7 @@ HERE
193
246
  title: #{title}
194
247
  date: #{date}
195
248
  ---
196
- *This is a test blog post page!*
249
+ *This is a temporary blog post page!*
197
250
  HERE
198
251
  f = File.new(path, "w")
199
252
  f.write(text)
@@ -201,13 +254,16 @@ HERE
201
254
  puts "Created new blog post #{title} at #{path}"
202
255
  end
203
256
 
204
- def self.render_page(templates, data, blog)
257
+ def self.render_page(templates, default_data, data, blog)
205
258
  if data.key?("template")
206
259
  Mustache.template = templates[data["template"]]
207
260
  else
208
261
  Mustache.template = templates[DEFAULT_TEMPLATE]
209
262
  end
210
263
  result = Mustache.new
264
+ default_data.each do |key, val|
265
+ result[key.to_sym] = val
266
+ end
211
267
  data.each do |key, val|
212
268
  next if key == "template"
213
269
  if key != "title"
@@ -262,7 +318,7 @@ HERE
262
318
  Dir.mkdir(name)
263
319
 
264
320
  paths = Array.new
265
- ["deploy", "static", "server", "templates", "pages"].each do |dir|
321
+ ["deploy", "static", "templates", "pages"].each do |dir|
266
322
  paths.push(File.join(name, dir))
267
323
  end
268
324
  ["css", "js", "imgs"].each do |dir|
@@ -278,7 +334,15 @@ HERE
278
334
 
279
335
  settings_file = <<HERE
280
336
  name: #{name}
281
- author: Your Name
337
+ author: Your Name
338
+ watermark: |
339
+ <p style="text-align: center;">
340
+ <small>Powered by <a href="https://rubygems.org/gems/solutus/versions/0.0.1">Solutus</a></small>
341
+ </p>
342
+ stylesheets: |
343
+ <link rel="stylesheet" type="text/css" href="/css/styles.css" />
344
+ scripts: |
345
+ <script></script>
282
346
  HERE
283
347
 
284
348
  styles_file = <<HERE
@@ -291,15 +355,17 @@ HERE
291
355
  <!DOCTYPE html>
292
356
  <head>
293
357
  <title>{{title}}</title>
294
- <link rel="stylesheet" type="text/css" href="/css/styles.css" />
358
+ {{{stylesheets}}}
295
359
  </head>
296
360
  <body>
297
361
  <div id="solutus-everything">
298
362
  {{#blog}}
299
363
  <h1>{{title}}</h1>
300
- {{date}}
364
+ {{{date}}}
301
365
  {{/blog}}
302
366
  {{{content}}}
367
+ {{{watermark}}}
368
+ {{{scripts}}}
303
369
  </div>
304
370
  </body>
305
371
  </html>
File without changes
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <title>Editing Site</title>
4
+ </head>
5
+ <body>
6
+ <h1>Editing Website</h1>
7
+ <p><a href="/">View Site</a></p>
8
+ <p>
9
+ <form method="post" action="/newpost">
10
+ <fieldset>
11
+ <legend>New Blog Post:</legend>
12
+ <p><label for="post-title">Title:</label> <input type="text" name="post-title"></p>
13
+ <p><button type="submit">Create</button></fieldset></p>
14
+ </fieldset>
15
+ </form>
16
+ </p>
17
+ </body>
18
+ </html>
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.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Wei
@@ -10,7 +10,7 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-05-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A miminal static site generator
13
+ description: A miminal static site generator and local Web frontend
14
14
  email: jeromew@berkeley.edu
15
15
  executables:
16
16
  - solutus
@@ -19,6 +19,8 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/solutus
21
21
  - lib/solutus.rb
22
+ - resources/editBlog.html
23
+ - resources/index.html
22
24
  homepage: https://github.com/jeromew21/solutus
23
25
  licenses:
24
26
  - MIT
@@ -42,5 +44,5 @@ rubyforge_project:
42
44
  rubygems_version: 2.7.6
43
45
  signing_key:
44
46
  specification_version: 4
45
- summary: A miminal static site generator
47
+ summary: simplicity
46
48
  test_files: []