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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3419bff1b3e18d863803c3decf44fd50eb59036c
4
- data.tar.gz: 46968ddc82d376fc110a8c78abe4e714a3e1f1e3
3
+ metadata.gz: beb7e9e69d585851e17270013820de3fe89e9c8a
4
+ data.tar.gz: 72f715c94455428c0363afa2a41f081885ee6265
5
5
  SHA512:
6
- metadata.gz: 9826ec840bb3429059e1a24235e99627257d2a2167c80fb274681a5c2785a46bf7aae696a80716d196299b6e44771bbb5834bdcb6ab28491dbabb4da6454d882
7
- data.tar.gz: b0573c644245434c3025087c8e8e9a5ba4c5cd176496284babaed1b5b0b0d31915369a9db3acdb98f6eadfa8a7c598579f2cb90881b18a139ad4ca524c3e12e9
6
+ metadata.gz: ec5220abae71f09770c6e9556d03d4af69432e07795916b91fad5dfb01d8fc42cbbff48188ac9bd3243e64d69c337318638c21cb8760595b3eeb85be276c9662
7
+ data.tar.gz: 10a6e53af78b91d3035679d65cd3506f7cbc228e7efd97a41b3f06b809a544af89d5266d468d16929bb29c63fb01373a01ad8e88dc1345823311e3fb7ffc2b99
data/README.md CHANGED
@@ -56,6 +56,8 @@ The Content files (.content) includes your content
56
56
 
57
57
  `[content]` - your content
58
58
 
59
+ ### Hint
60
+ For a root document (http://pathtoapp.tld/) path should be empty (path:,)
59
61
 
60
62
  ## Contributing
61
63
 
data/bin/rack-blogengine CHANGED
@@ -3,36 +3,36 @@ require 'rack/blogengine'
3
3
  require 'rack'
4
4
 
5
5
 
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
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
 
@@ -1,7 +1,7 @@
1
1
  require "rack/blogengine/version"
2
- require 'rack/blogengine/doc_parser'
3
- require 'rack/blogengine/application'
4
- require 'rack/blogengine/application_router'
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
- # 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
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
- module Blogengine
3
- class ApplicationRouter
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
- documents = DocParser.parseInDocuments(target)
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
- # Iterate through available docs, if nothing matched return nil
16
- documents.each do |doc|
17
- if doc[:path] == path
18
- route_response = {
19
- "route" => path,
20
- "response" => [status, header, [doc[:html]] ]
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
- return route_response
24
- end
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
- module Blogengine
3
- class DocParser
4
- # TODO Write Docparser
5
- # return
6
- # [{
7
- # path: "foo",
8
- # html: HTML
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
- # Parse in .content Documents.
14
- # @param target.
15
- # @return [Hash] Documents
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
- stylesheet = ::File.open("#{@target}/layout/style.css", "r")
22
- @css = stylesheet.read
23
- documents << { path:"/style.css", html: @css }
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
- getFileContents(item)
33
- fillFileContents(@html)
22
+ getFileContents(item)
23
+ @html = fillFileContents(@layout)
34
24
 
35
- @document = {path: @path, html: @html}
36
- documents << @document
37
- end
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
- return documents
40
- end
39
+ contentarray = content.split(",")
41
40
 
42
- # Get File Contents (path, title, content)
43
- # @param file
44
- def self.getFileContents(file)
45
- # do work on real items
46
- content_file = ::File.open("#{@target}/#{file}");
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
- contentarray = content.split(",")
47
+ if contentblock.include? "[title]:"
48
+ contentblock["[title]:"] = ""
49
+ @title = contentblock
50
+ end
50
51
 
51
- contentarray.each do |contentblock|
52
- if contentblock.include? "[path]:"
53
- contentblock["[path]:"] = ""
54
- @path = "/#{contentblock}"
55
- end
52
+ if contentblock.include? "[content]:"
53
+ contentblock["[content]:"] = ""
54
+ @content = contentblock
55
+ end
56
+ end
57
+ end
56
58
 
57
- if contentblock.include? "[title]:"
58
- contentblock["[title]:"] = ""
59
- @title = contentblock
60
- end
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
- if contentblock.include? "[content]:"
63
- contentblock["[content]:"] = ""
64
- @content = contentblock
65
- end
66
- end
67
- end
65
+ html.gsub! "{title}", @title
66
+ html["{content}"] = @content
68
67
 
69
- # Replace layout placeholder with content from .content file
70
- # @param layout
71
- # return [String] layout placeholder replaced with content
72
- def self.fillFileContents(layout)
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Blogengine
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4".freeze
4
4
  end
5
5
  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.3
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-10 00:00:00.000000000 Z
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler