rack-blogengine 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +1 -1
- data/README.md +4 -0
- data/Rakefile +9 -4
- data/{lib/rack/blogengine/files → assets}/config.yml +0 -0
- data/{lib/rack/blogengine/files → assets}/index.content +0 -0
- data/{lib/rack/blogengine/files → assets}/layout.html +0 -0
- data/assets/operator.rb +8 -0
- data/bin/rack-blogengine +4 -4
- data/lib/rack/blogengine.rb +15 -8
- data/lib/rack/blogengine/application.rb +8 -12
- data/lib/rack/blogengine/application_router.rb +25 -20
- data/lib/rack/blogengine/command_line_interface.rb +38 -38
- data/lib/rack/blogengine/doc_parser.rb +40 -43
- data/lib/rack/blogengine/document.rb +8 -8
- data/lib/rack/blogengine/methods.rb +13 -0
- data/lib/rack/blogengine/operator.rb +6 -6
- data/lib/rack/blogengine/version.rb +7 -1
- data/rack-blogengine.gemspec +4 -1
- data/test/application_router_test.rb +50 -0
- data/test/document_test.rb +31 -0
- data/test/test_helper.rb +49 -0
- metadata +93 -74
- data/lib/rack/blogengine/files/operator.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e31dc4ce6c8c6c9cb2bafc8d24cc0914693897fe
|
4
|
+
data.tar.gz: d26429eab938829b1327c67e63825287d5350b97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28af739b4183e622649a779dff8b54e75fac04ca6eaae4493f3249561891b8b22f80379e3a29a1c9d234fb8b27bd70be6596e779a61b7adfdd48d74bddc0d666
|
7
|
+
data.tar.gz: df05afe21a21150796675188e02fe4092e84af82c4c087ca1fa1bd32e2e1c105344c016d0f088ac328012559ca5da72fb7da40b4f4b39fc03d0f3dff515cf60e
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
2
3
|
|
3
|
-
|
4
|
+
namespace :test do
|
5
|
+
Rake::TestTask.new(:unit) do |t|
|
6
|
+
t.libs << "test"
|
7
|
+
t.test_files = FileList['test/*_test.rb']
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
end
|
4
11
|
|
5
|
-
|
6
|
-
|
7
|
-
task :default => :spec
|
12
|
+
task :default => 'test:unit'
|
File without changes
|
File without changes
|
File without changes
|
data/assets/operator.rb
ADDED
data/bin/rack-blogengine
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'rack/blogengine
|
2
|
+
require 'rack/blogengine'
|
3
3
|
|
4
4
|
if ARGV[0]
|
5
5
|
command = ARGV[0].to_sym
|
6
6
|
else
|
7
|
-
command =
|
7
|
+
command = ''.to_sym
|
8
8
|
end
|
9
9
|
|
10
10
|
target = ARGV[1]
|
11
|
-
target =
|
11
|
+
target = '' unless ARGV[1]
|
12
12
|
|
13
13
|
cli = Rack::Blogengine::CommandLineInterface.new
|
14
14
|
|
15
|
-
if target !=
|
15
|
+
if target != ''
|
16
16
|
cli.send(command, target)
|
17
17
|
else
|
18
18
|
cli.send(command)
|
data/lib/rack/blogengine.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require 'rack/blogengine/version'
|
2
|
+
require 'rack/blogengine/doc_parser'
|
3
|
+
require 'rack/blogengine/document'
|
4
|
+
require 'rack/blogengine/application'
|
5
|
+
require 'rack/blogengine/application_router'
|
6
|
+
require 'rack/blogengine/command_line_interface'
|
7
|
+
require 'rack/blogengine/operator'
|
8
|
+
require 'rack/blogengine/methods'
|
7
9
|
|
8
10
|
module Rack
|
9
|
-
|
11
|
+
#
|
12
|
+
# BlogEngine Module used for namespacing
|
13
|
+
# Used in all /lib files
|
14
|
+
#
|
15
|
+
# @author [benny]
|
16
|
+
#
|
17
|
+
module Blogengine
|
10
18
|
end
|
11
19
|
end
|
12
|
-
|
@@ -1,25 +1,21 @@
|
|
1
1
|
module Rack
|
2
2
|
module Blogengine
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Application is the callable middleware class
|
5
5
|
# run Rack::Blogengine::Application
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# @author [benny]
|
8
|
-
#
|
8
|
+
#
|
9
9
|
class Application
|
10
10
|
# Call Method for run this method as Rack Middleware.
|
11
11
|
# @param env Environment contains information such as path, headers etc...
|
12
12
|
# @return [Array] response Array
|
13
13
|
def self.call(env)
|
14
14
|
# Router for map docs to routes
|
15
|
-
route = ApplicationRouter.map_route(env, $documents)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#TODO Errorpage handling
|
20
|
-
return [404, {"Content-Type" => "text/html; charset=UTF-8"}, ["Page not found"]]
|
21
|
-
end
|
22
|
-
end
|
15
|
+
route = ApplicationRouter.map_route(env, $documents)
|
16
|
+
|
17
|
+
route['response']
|
18
|
+
end
|
23
19
|
end
|
24
20
|
end
|
25
|
-
end
|
21
|
+
end
|
@@ -1,34 +1,39 @@
|
|
1
1
|
module Rack
|
2
2
|
module Blogengine
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# ApplicationRouter routes the request to the proper, parsed .content (layout.html + .content) file
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# @author [benny]
|
7
|
-
#
|
7
|
+
#
|
8
8
|
class ApplicationRouter
|
9
9
|
# Maps documents to routes.
|
10
10
|
# @param env Env Contains path info etc...
|
11
|
-
# @param
|
11
|
+
# @param documents Documents which will be looked at
|
12
12
|
# @return [Hash] route Hash {:path => "/foo", :response => [Array]}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# Iterate through available docs, if nothing matched return nil
|
19
|
-
documents.each do |doc|
|
20
|
-
if doc[:path] == path
|
21
|
-
route_response = {
|
22
|
-
"path" => path,
|
23
|
-
"response" => [status, header, [doc[:html]] ]
|
24
|
-
}
|
13
|
+
class << self
|
14
|
+
def map_route(env, documents)
|
15
|
+
success_status = 200
|
16
|
+
header = { 'Content-Type' => 'text/html; charset=UTF-8' }
|
17
|
+
path = env['PATH_INFO']
|
25
18
|
|
26
|
-
|
19
|
+
# Iterate through available docs, if nothing matched return nil
|
20
|
+
documents.each do |doc|
|
21
|
+
if doc[:path] == path
|
22
|
+
route_response = {
|
23
|
+
'path' => path,
|
24
|
+
'response' => [success_status, header, [doc[:html]]]
|
25
|
+
}
|
26
|
+
|
27
|
+
return route_response
|
28
|
+
end
|
27
29
|
end
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
+
{ 'path' => '/error',
|
32
|
+
'response' =>
|
33
|
+
[404, { 'Content-Type' => 'text/html; charset=UTF-8' }, ['Page not found && no error page found']]
|
34
|
+
}
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
34
|
-
end
|
39
|
+
end
|
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'rack'
|
2
|
-
require 'rack/blogengine'
|
3
2
|
require 'yaml'
|
4
3
|
|
5
4
|
module Rack
|
6
5
|
module Blogengine
|
7
|
-
#
|
6
|
+
#
|
8
7
|
# This Class handles all cli input (running the app, generate folder skeleton)
|
9
|
-
#
|
8
|
+
#
|
10
9
|
# @author [benny]
|
11
|
-
#
|
10
|
+
#
|
12
11
|
class CommandLineInterface
|
13
12
|
def method_missing(name, *args)
|
14
13
|
puts "Command #{name} not available"
|
15
|
-
print
|
14
|
+
print 'Available Commands are: \n\n'
|
16
15
|
self.class.instance_methods(false).each do |method|
|
17
|
-
print "\t #{method}\n" unless method == :method_missing
|
16
|
+
print "\t #{method}\n" unless method == :method_missing # || method == :setup || method == :getConfig
|
18
17
|
end
|
19
18
|
print "\n"
|
20
19
|
end
|
@@ -22,46 +21,46 @@ module Rack
|
|
22
21
|
# Method to run the rack Application
|
23
22
|
# @param [String] target
|
24
23
|
def run(target)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
if target.empty?
|
25
|
+
puts 'Specify a targetfolder!'
|
26
|
+
else
|
27
|
+
if target.include?('/')
|
28
|
+
target = target.dup
|
29
|
+
target['/'] = ''
|
29
30
|
end
|
30
31
|
|
31
32
|
if Dir.exists?("#{target}")
|
32
33
|
system("cd #{target}")
|
33
34
|
|
34
35
|
targetfolder = "#{Dir.pwd}/#{target}"
|
35
|
-
config =
|
36
|
+
config = get_config(targetfolder)
|
36
37
|
|
37
38
|
app = Rack::Builder.new do
|
38
|
-
map
|
39
|
+
map '/assets' do
|
39
40
|
run Rack::Directory.new("#{targetfolder}/assets")
|
40
41
|
end
|
41
42
|
|
42
43
|
use Rack::CommonLogger
|
43
44
|
use Rack::ShowExceptions
|
44
45
|
use Rack::Lint
|
45
|
-
|
46
|
-
if config[
|
47
|
-
use Rack::Auth::Basic,
|
48
|
-
username == config[
|
46
|
+
|
47
|
+
if config['Usage'] == 'yes'
|
48
|
+
use Rack::Auth::Basic, 'Protected Area' do |username, password|
|
49
|
+
username == config['Username'] && password == config['Password']
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
52
|
-
# Parse in all Documents in cli.run(target)
|
53
|
+
# Parse in all Documents in cli.run(target)
|
53
54
|
# -> $documents are parsed in only once and then cached via a global variable
|
54
|
-
$documents = DocParser.
|
55
|
+
$documents = DocParser.parse_in_documents(targetfolder)
|
55
56
|
|
56
57
|
run Rack::Blogengine::Application
|
57
58
|
end
|
58
59
|
|
59
|
-
Rack::Server.start(
|
60
|
+
Rack::Server.start(app: app, Port: config['Port'], server: config['Server'])
|
60
61
|
else
|
61
|
-
puts
|
62
|
+
puts 'Target is not a folder!'
|
62
63
|
end
|
63
|
-
else
|
64
|
-
puts "Specify a targetfolder!"
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
@@ -80,22 +79,22 @@ module Rack
|
|
80
79
|
puts "\n\tSetting up essential Files\n"
|
81
80
|
|
82
81
|
# SET UP operator.rb
|
83
|
-
setup(
|
82
|
+
setup('operator.rb', "#{folder}/operator", true)
|
84
83
|
|
85
84
|
# SET UP config.yml
|
86
|
-
setup(
|
85
|
+
setup('config.yml', "#{folder}", true)
|
87
86
|
|
88
87
|
# SET UP index.content
|
89
|
-
setup(
|
88
|
+
setup('index.content', "#{folder}", true)
|
90
89
|
|
91
90
|
# SET UP layout.html
|
92
|
-
setup(
|
91
|
+
setup('layout.html', "#{folder}/assets/layout", true)
|
93
92
|
|
94
93
|
# SET UP style.css
|
95
|
-
setup(
|
94
|
+
setup('style.css', "#{folder}/assets/style", false)
|
96
95
|
|
97
96
|
# SET UP script.js
|
98
|
-
setup(
|
97
|
+
setup('script.js', "#{folder}/assets/js", false)
|
99
98
|
|
100
99
|
puts "\n\tSetup finished! Have Fun\n"
|
101
100
|
puts "\tTo test it type rack-blogengine run #{folder}"
|
@@ -118,23 +117,24 @@ module Rack
|
|
118
117
|
puts "\tSet up #{path}/#{name}\n"
|
119
118
|
system("touch #{path}/#{name}")
|
120
119
|
if essential
|
121
|
-
|
120
|
+
assetspath = "#{Rack::Blogengine.root}/assets/#{name}"
|
121
|
+
content = IO.read(assetspath)
|
122
122
|
::File.open("#{path}/#{name}", 'w') { |file| file.write(content) }
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
# Get YAML Config settings for Server.start && HTTPauth
|
127
|
-
def
|
128
|
-
|
127
|
+
def get_config(target)
|
128
|
+
config_yaml = YAML.load(::File.open("#{target}/config.yml"))
|
129
129
|
|
130
|
-
port =
|
131
|
-
server =
|
132
|
-
username =
|
133
|
-
password =
|
134
|
-
usage =
|
130
|
+
port = config_yaml['Port']
|
131
|
+
server = config_yaml['Server']
|
132
|
+
username = config_yaml['HTTPauth']['username'].to_s.strip
|
133
|
+
password = config_yaml['HTTPauth']['password'].to_s.strip
|
134
|
+
usage = config_yaml['HTTPauth']['usage']
|
135
135
|
|
136
|
-
|
136
|
+
{ 'Port' => port, 'Server' => server, 'Username' => username, 'Password' => password, 'Usage' => usage }
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
140
|
-
end
|
140
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
1
|
module Rack
|
2
2
|
module Blogengine
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Prepares the documents for the response
|
5
5
|
# Reads in layout.html and .content file -> merged html
|
6
6
|
# Sort documents by date
|
7
7
|
# Execute Content Operator after all documents has been parsed in
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# @author [benny]
|
10
|
-
#
|
10
|
+
#
|
11
11
|
class DocParser
|
12
12
|
# Parse in .content Documents.
|
13
13
|
# @param target.
|
14
|
-
# @return [Hash] Documents
|
15
|
-
def self.
|
14
|
+
# @return [Hash] Documents
|
15
|
+
def self.parse_in_documents(target)
|
16
16
|
@target = target
|
17
17
|
documents = []
|
18
18
|
|
19
|
-
layout_file = ::File.open("#{@target}/assets/layout/layout.html",
|
19
|
+
layout_file = ::File.open("#{@target}/assets/layout/layout.html", 'r')
|
20
20
|
@layout = layout_file.read
|
21
21
|
|
22
22
|
Dir.foreach("#{target}/") do |item|
|
23
|
-
extension = item.split(
|
24
|
-
next if item == '.'
|
25
|
-
|
26
|
-
|
27
|
-
@html =
|
28
|
-
|
23
|
+
extension = item.split('.')[1]
|
24
|
+
next if item == '.' || item == '..' || extension != 'content'
|
25
|
+
|
26
|
+
get_file_contents(item)
|
27
|
+
@html = fill_file_contents(@layout)
|
28
|
+
|
29
29
|
@document = Document.new
|
30
30
|
@document.path = @path
|
31
|
-
@document.html = @html
|
31
|
+
@document.html = @html.gsub(/\s+/, ' ').strip
|
32
32
|
@document.title = @title
|
33
33
|
@document.date = @date
|
34
34
|
|
@@ -37,53 +37,52 @@ module Rack
|
|
37
37
|
|
38
38
|
sort documents
|
39
39
|
|
40
|
-
# Has to exec operator after all docs were read,
|
40
|
+
# Has to exec operator after all docs were read,
|
41
|
+
# so documents are available for operators (list all docs, etc...)
|
41
42
|
documents.each do |document|
|
42
43
|
document.exec_content_operator(documents, @target)
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
+
documents.map do |document|
|
46
47
|
document.to_hash
|
47
48
|
end
|
48
|
-
|
49
|
-
return documentshashed
|
50
49
|
end
|
51
50
|
|
52
51
|
# Get File Contents (path, title, content)
|
53
52
|
# @param [String] file
|
54
|
-
def self.
|
55
|
-
content_file = ::File.open("#{@target}/#{file}")
|
53
|
+
def self.get_file_contents(file)
|
54
|
+
content_file = ::File.open("#{@target}/#{file}")
|
56
55
|
content = content_file.read
|
57
56
|
|
58
57
|
# Replace Closing tags
|
59
|
-
content[
|
60
|
-
content[
|
61
|
-
content[
|
62
|
-
content[
|
63
|
-
|
64
|
-
contentarray = content.split(
|
58
|
+
content['/path'] = '/close'
|
59
|
+
content['/title'] = '/close'
|
60
|
+
content['/content'] = '/close'
|
61
|
+
content['/date'] = '/close'
|
62
|
+
|
63
|
+
contentarray = content.split('[/close]')
|
65
64
|
|
66
65
|
contentarray.each do |contentblock|
|
67
|
-
if contentblock.include?
|
68
|
-
contentblock[
|
66
|
+
if contentblock.include? '[path]:'
|
67
|
+
contentblock['[path]:'] = ''
|
69
68
|
@path = "/#{contentblock}"
|
70
69
|
end
|
71
70
|
|
72
|
-
if contentblock.include?
|
73
|
-
contentblock[
|
71
|
+
if contentblock.include? '[title]:'
|
72
|
+
contentblock['[title]:'] = ''
|
74
73
|
@title = contentblock.strip
|
75
74
|
end
|
76
75
|
|
77
|
-
if contentblock.include?
|
78
|
-
contentblock[
|
76
|
+
if contentblock.include? '[content]:'
|
77
|
+
contentblock['[content]:'] = ''
|
79
78
|
@content = contentblock.strip
|
80
79
|
end
|
81
80
|
|
82
|
-
if contentblock.include?
|
83
|
-
contentblock[
|
84
|
-
datearray = contentblock.split(
|
81
|
+
if contentblock.include? '[date]:'
|
82
|
+
contentblock['[date]:'] = ''
|
83
|
+
datearray = contentblock.split(',')
|
85
84
|
datearray = datearray.map do |date|
|
86
|
-
date
|
85
|
+
date.to_i
|
87
86
|
end
|
88
87
|
|
89
88
|
@date = Date.new(datearray[0], datearray[1], datearray[2])
|
@@ -94,14 +93,12 @@ module Rack
|
|
94
93
|
# Replace layout placeholder with content from .content file
|
95
94
|
# @param [String] layout
|
96
95
|
# return [String] html placeholder replaced with content
|
97
|
-
def self.
|
96
|
+
def self.fill_file_contents(layout)
|
98
97
|
html = layout.dup
|
99
98
|
|
100
|
-
html.gsub!
|
101
|
-
html[
|
102
|
-
html.gsub!
|
103
|
-
|
104
|
-
return html
|
99
|
+
html.gsub! '{title}', @title
|
100
|
+
html['{content}'] = @content
|
101
|
+
html.gsub! '{date}', @date.strftime('%d.%m.%Y')
|
105
102
|
end
|
106
103
|
|
107
104
|
# Sort documents array by date of each documenthash
|
@@ -113,8 +110,8 @@ module Rack
|
|
113
110
|
a.date.to_time.to_i <=> b.date.to_time.to_i
|
114
111
|
end
|
115
112
|
|
116
|
-
|
113
|
+
documents
|
117
114
|
end
|
118
115
|
end
|
119
116
|
end
|
120
|
-
end
|
117
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module Rack
|
2
2
|
module Blogengine
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Document Class
|
5
5
|
# Contains attributes path, html, title, date
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# @author [benny]
|
8
|
-
#
|
8
|
+
#
|
9
9
|
class Document
|
10
10
|
attr_accessor :path, :html, :title, :date
|
11
11
|
|
12
12
|
def to_hash
|
13
13
|
hash = {}
|
14
14
|
instance_variables.each do |var|
|
15
|
-
unless var.to_s ==
|
16
|
-
hash[var.to_s.delete(
|
17
|
-
end
|
15
|
+
unless var.to_s == '@title' || var.to_s == '@date'
|
16
|
+
hash[var.to_s.delete('@').to_sym] = instance_variable_get(var)
|
17
|
+
end
|
18
18
|
end
|
19
19
|
hash
|
20
20
|
end
|
@@ -25,9 +25,9 @@ module Rack
|
|
25
25
|
operator = Operator.new(target)
|
26
26
|
operatorhtml = operator.send(contentoperator, documents, @html)
|
27
27
|
|
28
|
-
@html[
|
28
|
+
@html['{% ' + contentoperator.to_s + ' %}'] = operatorhtml
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
#
|
1
|
+
#
|
2
2
|
# Operator Class loads in UserOperators on initialize
|
3
3
|
# Methods defined in this Class are "Default Operators"
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# @author [benny]
|
6
|
-
#
|
6
|
+
#
|
7
7
|
class Operator
|
8
8
|
def initialize(target)
|
9
9
|
Dir.foreach("#{target}/operator/") do |item|
|
10
|
-
extension = item.split(
|
11
|
-
next if item == '.'
|
10
|
+
extension = item.split('.')[1]
|
11
|
+
next if item == '.' || item == '..' || extension != 'rb'
|
12
12
|
require "#{target}/operator/#{item}"
|
13
13
|
end
|
14
14
|
|
@@ -16,4 +16,4 @@ class Operator
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# define default operators here
|
19
|
-
end
|
19
|
+
end
|
data/rack-blogengine.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["klotz.benjamin@yahoo.de"]
|
11
11
|
spec.description = %q{Blogengine based on rack applications}
|
12
12
|
spec.summary = "#{spec.description}"
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "http://www.bennyklotz.at"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -21,6 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec", ">= 2.0.0"
|
24
|
+
spec.add_development_dependency "test-unit"
|
25
|
+
spec.add_development_dependency "test-unit-notify"
|
26
|
+
spec.add_development_dependency "rack-test"
|
24
27
|
|
25
28
|
spec.add_runtime_dependency "rack"
|
26
29
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
#
|
4
|
+
# TestClass for ApplicationRouter
|
5
|
+
#
|
6
|
+
# @author [benny]
|
7
|
+
#
|
8
|
+
class ApplicationRouterTest < Test::Unit::TestCase
|
9
|
+
include Rack::Test::Methods
|
10
|
+
|
11
|
+
def setup
|
12
|
+
# TODO: Use Fake Data - Don't generate a whole testfolder....
|
13
|
+
cli = Rack::Blogengine::CommandLineInterface.new
|
14
|
+
capture_stdout { cli.generate(testpath) }
|
15
|
+
|
16
|
+
documents = Rack::Blogengine::DocParser.parse_in_documents(testpath)
|
17
|
+
env_fail = { 'PATH_INFO' => '/fail' }
|
18
|
+
env_success = { 'PATH_INFO' => '/' }
|
19
|
+
|
20
|
+
@route_success = Rack::Blogengine::ApplicationRouter.map_route(env_success, documents)
|
21
|
+
@route_fail = Rack::Blogengine::ApplicationRouter.map_route(env_fail, documents)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_map_route_general
|
25
|
+
assert_equal(Hash, @route_success.class, 'Route should be a hash')
|
26
|
+
|
27
|
+
# Check Hash keys
|
28
|
+
assert_true(@route_success.key?('path'), 'Route should contain a path')
|
29
|
+
assert_true(@route_success.key?('response'), 'Route should contain a response')
|
30
|
+
|
31
|
+
# Check path
|
32
|
+
assert_equal(String, @route_success['path'].class, 'Path should be a string')
|
33
|
+
|
34
|
+
# Check response
|
35
|
+
assert_equal(Array, @route_success['response'].class, 'Response should be an Array')
|
36
|
+
assert_equal(Fixnum, @route_success['response'][0].class, 'Status should be a Fixnum')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_map_route_on_success
|
40
|
+
assert_equal(200, @route_success['response'][0], 'Status should be 200')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_map_route_on_fail
|
44
|
+
assert_equal(404, @route_fail['response'][0], 'Status should be 404')
|
45
|
+
end
|
46
|
+
|
47
|
+
def teardown
|
48
|
+
system("rm -rf #{testpath}")
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
#
|
4
|
+
# TestClass for Documents
|
5
|
+
#
|
6
|
+
# @author [benny]
|
7
|
+
#
|
8
|
+
class DocumentTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@document = Rack::Blogengine::Document.new
|
11
|
+
|
12
|
+
@document.title = 'testtitle'
|
13
|
+
@document.path = '/test'
|
14
|
+
@document.date = '20-20-2014'
|
15
|
+
@document.html = '<html><h1>Test</h1></html>'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_document_has_content
|
19
|
+
assert_equal('testtitle', @document.title, 'Document should contain the testtitle')
|
20
|
+
assert_equal('/test', @document.path, 'Document should contain the test path')
|
21
|
+
assert_equal('20-20-2014', @document.date, 'Document should contain the test date')
|
22
|
+
assert_equal('<html><h1>Test</h1></html>', @document.html, 'Document should contain the test html')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_document_to_hash
|
26
|
+
hashed = @document.to_hash
|
27
|
+
|
28
|
+
assert_true(hashed.key?(:path), 'Hashed Document should contain the path')
|
29
|
+
assert_true(hashed.key?(:html), 'Hashed Document should contain parsed html')
|
30
|
+
end
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Minitest
|
2
|
+
# require 'minitest/autorun'
|
3
|
+
# require 'minitest/pride' # for colored output
|
4
|
+
# require "test_notifier/runner/minitest"
|
5
|
+
|
6
|
+
# Real TestUnit
|
7
|
+
require 'test/unit'
|
8
|
+
require 'test/unit/notify'
|
9
|
+
require 'rack/blogengine'
|
10
|
+
require 'rack/test'
|
11
|
+
|
12
|
+
# alternative to require_relative
|
13
|
+
# rake install in gem dir and then
|
14
|
+
# require 'mygem'
|
15
|
+
|
16
|
+
# class Hash
|
17
|
+
# method for usage with assert_boolean
|
18
|
+
# -> for failing it needs nil instead of false (which #has_key? returns in failing case)
|
19
|
+
# NOT Needed use assert_true instead...
|
20
|
+
# def hash_key?(key)
|
21
|
+
# if self.has_key?(key)
|
22
|
+
# return true
|
23
|
+
# else
|
24
|
+
# return nil
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Opening Core Class Object for testpath method
|
31
|
+
#
|
32
|
+
# @author [benny]
|
33
|
+
#
|
34
|
+
class Object
|
35
|
+
def testpath
|
36
|
+
"#{Rack::Blogengine.root}/testfolder"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def capture_stdout(&block)
|
41
|
+
original_stdout = $stdout
|
42
|
+
$stdout = fake = StringIO.new
|
43
|
+
begin
|
44
|
+
yield
|
45
|
+
ensure
|
46
|
+
$stdout = original_stdout
|
47
|
+
end
|
48
|
+
fake.string
|
49
|
+
end
|
metadata
CHANGED
@@ -1,84 +1,101 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-blogengine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Benny1992
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
date: 2014-02-07 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- -
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :development
|
16
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: "1.3"
|
21
21
|
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
22
|
type: :development
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rake
|
26
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- &id004
|
29
|
+
- ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
35
32
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id002
|
35
|
+
- !ruby/object:Gem::Dependency
|
42
36
|
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
37
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
45
39
|
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
40
|
+
- !ruby/object:Gem::Version
|
47
41
|
version: 2.0.0
|
42
|
+
prerelease: false
|
48
43
|
type: :development
|
44
|
+
version_requirements: *id003
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: test-unit
|
47
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- *id004
|
49
50
|
prerelease: false
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id005
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: test-unit-notify
|
55
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- *id004
|
58
|
+
prerelease: false
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id006
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rack-test
|
63
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- *id004
|
66
|
+
prerelease: false
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id007
|
69
|
+
- !ruby/object:Gem::Dependency
|
56
70
|
name: rack
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
-
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
71
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- *id004
|
63
74
|
prerelease: false
|
64
|
-
|
65
|
-
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id008
|
69
77
|
description: Blogengine based on rack applications
|
70
|
-
email:
|
78
|
+
email:
|
71
79
|
- klotz.benjamin@yahoo.de
|
72
|
-
executables:
|
80
|
+
executables:
|
73
81
|
- rack-blogengine
|
74
82
|
extensions: []
|
83
|
+
|
75
84
|
extra_rdoc_files: []
|
76
|
-
|
77
|
-
|
85
|
+
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .rspec
|
89
|
+
- .rubocop.yml
|
90
|
+
- .travis.yml
|
78
91
|
- Gemfile
|
79
92
|
- LICENSE.txt
|
80
93
|
- README.md
|
81
94
|
- Rakefile
|
95
|
+
- assets/config.yml
|
96
|
+
- assets/index.content
|
97
|
+
- assets/layout.html
|
98
|
+
- assets/operator.rb
|
82
99
|
- bin/rack-blogengine
|
83
100
|
- lib/rack/blogengine.rb
|
84
101
|
- lib/rack/blogengine/application.rb
|
@@ -86,36 +103,38 @@ files:
|
|
86
103
|
- lib/rack/blogengine/command_line_interface.rb
|
87
104
|
- lib/rack/blogengine/doc_parser.rb
|
88
105
|
- lib/rack/blogengine/document.rb
|
89
|
-
- lib/rack/blogengine/
|
90
|
-
- lib/rack/blogengine/files/index.content
|
91
|
-
- lib/rack/blogengine/files/layout.html
|
92
|
-
- lib/rack/blogengine/files/operator.rb
|
106
|
+
- lib/rack/blogengine/methods.rb
|
93
107
|
- lib/rack/blogengine/operator.rb
|
94
108
|
- lib/rack/blogengine/version.rb
|
95
109
|
- rack-blogengine.gemspec
|
96
|
-
|
97
|
-
|
110
|
+
- test/application_router_test.rb
|
111
|
+
- test/document_test.rb
|
112
|
+
- test/test_helper.rb
|
113
|
+
homepage: http://www.bennyklotz.at
|
114
|
+
licenses:
|
98
115
|
- MIT
|
99
116
|
metadata: {}
|
117
|
+
|
100
118
|
post_install_message:
|
101
119
|
rdoc_options: []
|
102
|
-
|
120
|
+
|
121
|
+
require_paths:
|
103
122
|
- lib
|
104
123
|
- spec
|
105
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
requirements:
|
112
|
-
- - ">="
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
version: '0'
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- *id004
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- *id004
|
115
130
|
requirements: []
|
131
|
+
|
116
132
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.2.
|
133
|
+
rubygems_version: 2.2.2
|
118
134
|
signing_key:
|
119
135
|
specification_version: 4
|
120
136
|
summary: Blogengine based on rack applications
|
121
|
-
test_files:
|
137
|
+
test_files:
|
138
|
+
- test/application_router_test.rb
|
139
|
+
- test/document_test.rb
|
140
|
+
- test/test_helper.rb
|