rack-blogengine 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/bin/rack-blogengine +31 -31
- data/lib/rack/blogengine.rb +3 -3
- data/lib/rack/blogengine/application.rb +12 -12
- data/lib/rack/blogengine/application_router.rb +26 -23
- data/lib/rack/blogengine/doc_parser.rb +58 -64
- data/lib/rack/blogengine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beb7e9e69d585851e17270013820de3fe89e9c8a
|
4
|
+
data.tar.gz: 72f715c94455428c0363afa2a41f081885ee6265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec5220abae71f09770c6e9556d03d4af69432e07795916b91fad5dfb01d8fc42cbbff48188ac9bd3243e64d69c337318638c21cb8760595b3eeb85be276c9662
|
7
|
+
data.tar.gz: 10a6e53af78b91d3035679d65cd3506f7cbc228e7efd97a41b3f06b809a544af89d5266d468d16929bb29c63fb01373a01ad8e88dc1345823311e3fb7ffc2b99
|
data/README.md
CHANGED
data/bin/rack-blogengine
CHANGED
@@ -3,36 +3,36 @@ require 'rack/blogengine'
|
|
3
3
|
require 'rack'
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
6
|
+
command = ARGV[0]
|
7
|
+
|
8
|
+
if ARGV[1]
|
9
|
+
target = ARGV[1]
|
10
|
+
else
|
11
|
+
target = "";
|
12
|
+
end
|
13
|
+
|
14
|
+
if command == "run"
|
15
|
+
#To stuff here
|
16
|
+
unless target.empty?
|
17
|
+
$targetfolder = target
|
18
|
+
app = Rack::Builder.new do
|
19
|
+
use Rack::CommonLogger
|
20
|
+
use Rack::ShowExceptions
|
21
|
+
|
22
|
+
map "/images" do
|
23
|
+
run Rack::Directory.new("#{$targetfolder}/images")
|
24
|
+
end
|
25
|
+
|
26
|
+
use Rack::Lint
|
27
|
+
run Rack::Blogengine::Application
|
28
|
+
end
|
29
|
+
|
30
|
+
Rack::Server.start( :app => app )
|
31
|
+
else
|
32
|
+
puts "Specify a targetfolder!"
|
33
|
+
end
|
34
|
+
else
|
35
|
+
puts "Use rake-blogengine run!"
|
36
|
+
end
|
37
37
|
|
38
38
|
|
data/lib/rack/blogengine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rack/blogengine/version"
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "rack/blogengine/doc_parser"
|
3
|
+
require "rack/blogengine/application"
|
4
|
+
require "rack/blogengine/application_router"
|
5
5
|
|
6
6
|
module Rack
|
7
7
|
module Blogengine
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Rack
|
2
2
|
module Blogengine
|
3
3
|
class Application
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
# Call Method for run this method as Rack Middleware.
|
5
|
+
# @param env Environment contains information such as path, headers etc...
|
6
|
+
# @return [Array] response Array
|
7
|
+
def self.call(env)
|
8
|
+
# Router for map docs to routes
|
9
|
+
route = ApplicationRouter.map_route(env, $targetfolder)
|
10
|
+
if route
|
11
|
+
return route["response"]
|
12
|
+
else
|
13
|
+
return [404, {"Content-Type" => "text/html; charset=UTF-8"}, ["Page not found"]]
|
14
|
+
end
|
15
|
+
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,30 +1,33 @@
|
|
1
1
|
module Rack
|
2
|
-
|
3
|
-
|
4
|
-
# Maps documents to routes.
|
5
|
-
# @param env Env Contains path info etc...
|
6
|
-
# @param target Target folder
|
7
|
-
# @return [Hash] route Hash {:path => "/foo", :response => [Array]}
|
8
|
-
def self.map_route(env, target)
|
9
|
-
status = 200
|
10
|
-
header = {"Content-Type" => "text/html; charset=UTF-8"}
|
11
|
-
path = env["PATH_INFO"]
|
2
|
+
module Blogengine
|
3
|
+
class ApplicationRouter
|
12
4
|
|
13
|
-
|
5
|
+
# Maps documents to routes.
|
6
|
+
# @param env Env Contains path info etc...
|
7
|
+
# @param target Target folder
|
8
|
+
# @return [Hash] route Hash {:path => "/foo", :response => [Array]}
|
9
|
+
def self.map_route(env, target)
|
10
|
+
status = 200
|
11
|
+
header = {"Content-Type" => "text/html; charset=UTF-8"}
|
12
|
+
path = env["PATH_INFO"]
|
13
|
+
|
14
|
+
documents = DocParser.parseInDocuments(target)
|
15
|
+
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
# Iterate through available docs, if nothing matched return nil
|
18
|
+
documents.each do |doc|
|
19
|
+
if doc[:path] == path
|
20
|
+
route_response = {
|
21
|
+
"route" => path,
|
22
|
+
"response" => [status, header, [doc[:html]] ]
|
23
|
+
}
|
24
|
+
|
25
|
+
return route_response
|
26
|
+
end
|
27
|
+
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
return nil
|
27
|
-
end
|
29
|
+
return nil
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
@@ -1,78 +1,72 @@
|
|
1
1
|
module Rack
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
# HTML contains Content, Style, JS etc...
|
2
|
+
module Blogengine
|
3
|
+
class DocParser
|
4
|
+
# Parse in .content Documents.
|
5
|
+
# @param target.
|
6
|
+
# @return [Hash] Documents
|
7
|
+
def self.parseInDocuments(target)
|
8
|
+
@target = target
|
9
|
+
documents = []
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def self.parseInDocuments(target)
|
17
|
-
@target = target
|
18
|
-
documents = []
|
11
|
+
stylesheet = ::File.open("#{@target}/layout/style.css", "r")
|
12
|
+
@css = stylesheet.read
|
13
|
+
documents << { path:"/style.css", html: @css }
|
19
14
|
|
15
|
+
layout_file = ::File.open("#{@target}/layout/layout.html", "r")
|
16
|
+
@layout = layout_file.read
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
layout_file = ::File.open("#{@target}/layout/layout.html", "r")
|
26
|
-
@html = layout_file.read
|
27
|
-
|
28
|
-
Dir.foreach("#{target}/") do |item|
|
29
|
-
extension = item.split(".")[1]
|
30
|
-
next if item == '.' or item == '..' or extension != "content"
|
18
|
+
Dir.foreach("#{target}/") do |item|
|
19
|
+
extension = item.split(".")[1]
|
20
|
+
next if item == '.' or item == '..' or extension != "content"
|
31
21
|
|
32
|
-
|
33
|
-
|
22
|
+
getFileContents(item)
|
23
|
+
@html = fillFileContents(@layout)
|
34
24
|
|
35
|
-
|
36
|
-
|
37
|
-
|
25
|
+
@document = {path: @path, html: @html}
|
26
|
+
documents << @document
|
27
|
+
end
|
28
|
+
|
29
|
+
return documents
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get File Contents (path, title, content)
|
33
|
+
# @param file
|
34
|
+
def self.getFileContents(file)
|
35
|
+
# do work on real items
|
36
|
+
content_file = ::File.open("#{@target}/#{file}");
|
37
|
+
content = content_file.read
|
38
38
|
|
39
|
-
|
40
|
-
end
|
39
|
+
contentarray = content.split(",")
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
content = content_file.read
|
41
|
+
contentarray.each do |contentblock|
|
42
|
+
if contentblock.include? "[path]:"
|
43
|
+
contentblock["[path]:"] = ""
|
44
|
+
@path = "/#{contentblock}"
|
45
|
+
end
|
48
46
|
|
49
|
-
|
47
|
+
if contentblock.include? "[title]:"
|
48
|
+
contentblock["[title]:"] = ""
|
49
|
+
@title = contentblock
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
if contentblock.include? "[content]:"
|
53
|
+
contentblock["[content]:"] = ""
|
54
|
+
@content = contentblock
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
# Replace layout placeholder with content from .content file
|
60
|
+
# @param layout
|
61
|
+
# return [String] html placeholder replaced with content
|
62
|
+
def self.fillFileContents(layout)
|
63
|
+
html = layout.dup
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
@content = contentblock
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
65
|
+
html.gsub! "{title}", @title
|
66
|
+
html["{content}"] = @content
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
layout.gsub! "{title}", @title
|
74
|
-
layout["{content}"] = @content
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
68
|
+
return html
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
78
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-blogengine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benny1992
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|