Class: Solutus::Solutus_Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Solutus::Solutus_Server
- Defined in:
- lib/solutus.rb
Defined Under Namespace
Classes: ServerStache
Constant Summary collapse
- CSS =
File.read(File.join(File.dirname(File.(__FILE__)), '../resources', "style.css"))
- FILE_EXCLUDES =
['password.txt', '.gitignore', 'nohup.out', 'log']
- UPLOAD_DIR_SUFF =
'i'- UPLOAD_DIR =
File.join(STATIC_PATH, UPLOAD_DIR_SUFF)
Instance Method Summary collapse
- #blog_select ⇒ Object
- #page_select ⇒ Object
- #path_to_resources ⇒ Object
- #render_edit_file(path) ⇒ Object
- #render_edit_page(path) ⇒ Object
- #render_edit_post(path, url = "/") ⇒ Object
- #render_file_upload_dirs ⇒ Object
- #render_files ⇒ Object
- #render_index ⇒ Object
- #render_local(f, data) ⇒ Object
- #render_login(message = "") ⇒ Object
- #send_404 ⇒ Object
- #write_log(stuff) ⇒ Object
Instance Method Details
#blog_select ⇒ Object
518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/solutus.rb', line 518 def blog_select result = "<select name=\"post-path\">\n" Solutus.blog_urls.each do |yr, arr| sorted = arr.sort_by {|k| k["date"]} .reverse sorted.each do |blog| title = blog["title"] path = blog["file_path"] url = blog["url"] result += "<option value=\"#{path},#{url}\">#{title}</option>\n" end end result += "</select>" result end |
#page_select ⇒ Object
470 471 472 473 474 475 476 477 478 479 |
# File 'lib/solutus.rb', line 470 def page_select result = "<select name=\"page-path\">\n" Solutus.page_urls.each do |page| path = page["file_path"] title = page["title"] result += "<option value=\"#{path}\">#{title}</option>\n" end result += "</select>" result end |
#path_to_resources ⇒ Object
75 76 77 |
# File 'lib/solutus.rb', line 75 def path_to_resources File.join(File.dirname(File.(__FILE__)), '../resources') end |
#render_edit_file(path) ⇒ Object
330 331 332 333 334 335 336 337 |
# File 'lib/solutus.rb', line 330 def render_edit_file(path) #TODO: do smth diff for YML files... ServerStache.template = File.read(File.join(path_to_resources, "editFile.html")) result = ServerStache.new result[:content] = File.read(path) result[:path] = path result.render end |
#render_edit_page(path) ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/solutus.rb', line 343 def render_edit_page(path) f = File.open(File.join(path_to_resources, "editPage.html"), "r") template = "" f.each_line do |line| template += line end f.close f = File.open(path, "r") file_contents = "" f.each_line do |line| file_contents += line end data = YAML.load(file_contents) ServerStache.template = template result = ServerStache.new result[:css] = CSS result[:title] = data["title"] result[:path] = path link = path.split("/")[-1].split(".")[0] if ["error", "index"].include?(link) link = link + ".html" end result[:link] = link settings.global_settings.each do |key, val| result[key.to_sym] = val end page_html = Solutus.render_page(Solutus.templates, settings.global_settings, data) parser = Nokogiri::HTML(page_html) parser.at_css("#solutus-content")['contenteditable'] = true parser.at_css("#solutus-content")['style'] = "border: 1px black dashed" result[:everything] = parser.at_css("#solutus-everything") result.render end |
#render_edit_post(path, url = "/") ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/solutus.rb', line 380 def render_edit_post(path, url="/") f = File.open(File.join(path_to_resources, "editBlog.html"), "r") template = "" f.each_line do |line| template += line end f.close SolutusStache.template = template result = SolutusStache.new f = File.open(path, "r") file_contents = "" f.each_line do |line| file_contents += line end data = YAML.load(file_contents) result[:css] = CSS result[:title] = data["title"] result[:date] = data["date"].strftime(BLOG_DATE_FORMAT) result[:markdown] = file_contents.split("---")[-1] result[:link] = url result[:canview] = url != "/" result[:path] = path result[:subtitle] = data["subtitle"] result.render end |
#render_file_upload_dirs ⇒ Object
505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/solutus.rb', line 505 def render_file_upload_dirs result = '' unless File.directory?(UPLOAD_DIR) FileUtils.mkdir_p(UPLOAD_DIR) end Dir.entries(UPLOAD_DIR).each do |d| if (d != '.' && d != '..') && File.directory?(File.join(UPLOAD_DIR, d)) result += "<option>#{d}</option>" end end result end |
#render_files ⇒ Object
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/solutus.rb', line 481 def render_files result = "<select name=\"path\">\n" dirs = [".", "static/css", "templates", "pages/site-pages"] dirs.each do |dir| result += "<optgroup label='#{dir}'>" if dir == "." files = Dir.entries(dir).select {|f| !File.directory? f} else files = Solutus.relative_path_to_all_files_in_dir(dir) end files.each do |filename| if !FILE_EXCLUDES.include?(filename) path = File.join(dir, filename) if File.file?(path) result += "<option value=\"#{path}\">#{filename}</option>\n" end end end result += "</optgroup>" end result += "</select>" result end |
#render_index ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/solutus.rb', line 417 def render_index f = File.open(File.join(path_to_resources, "index.html"), "r") template = "" f.each_line do |line| template += line end f.close SolutusStache.template = template result = SolutusStache.new settings.global_settings.each do |key, val| result[key.to_sym] = val end dirs = Dir.entries(SITE_PAGES_PATH) puts dirs dir_res = '' dirs.each do |d| if File.directory?(File.join(SITE_PAGES_PATH, d)) && d != ".." val = d + "/" if val == '.' val = "/" end dir_res += "<option value='#{d}'>#{val}</option>" end end result[:page_paths] = dir_res result[:blogs] = blog_select result[:pages] = page_select result[:css] = CSS result[:files] = render_files result[:file_upload_paths] = render_file_upload_dirs result[:version] = VERSION result.render end |
#render_local(f, data) ⇒ Object
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/solutus.rb', line 451 def render_local(f, data) f = File.open(File.join(path_to_resources, f), "r") template = "" f.each_line do |line| template += line end f.close SolutusStache.template = template result = SolutusStache.new settings.global_settings.each do |key, val| result[key.to_sym] = val end data.each do |key, val| result[key.to_sym] = val end result[:css] = CSS result.render end |
#render_login(message = "") ⇒ Object
409 410 411 412 413 414 415 |
# File 'lib/solutus.rb', line 409 def render_login(="") ServerStache.template = File.read(File.join(path_to_resources, "login.html")) result = ServerStache.new result[:message] = result[:css] = CSS result.render end |
#send_404 ⇒ Object
339 340 341 |
# File 'lib/solutus.rb', line 339 def send_404 send_file File.join(path_to_resources, "404.html") end |
#write_log(stuff) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/solutus.rb', line 318 def write_log(stuff) times = Time.now.getlocal('-07:00') if !File.file?(LOG_FILE) f = File.new(LOG_FILE, 'w') f.write("#{times} (PST) Creating log file\n") f.close end f = File.open(LOG_FILE, 'a') f.write("#{times} #{stuff}\n") f.close end |