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 CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 03d29dbb67f31e4c0f1370fbdf0827c69b91d9e5
4
- data.tar.gz: cc3f7d24d61d883e39b9b2bc7a1f0b674030c934
5
- SHA512:
6
- metadata.gz: 6a3ba61a4ff79c4468f3d13f4b0d38996340c1562ee25700420c431c0a7f84864d0f337c39e9b4edd5c93fa96db5c63b5762bb76c2e287b5b9d99648df290687
7
- data.tar.gz: e4323d8c9705400d843e9c657bfb9c17779656782935ba1fca02068f8ad5bcc4ac7ae2f0ed5322c7cd607b7d44f2e6a8135f1389821881040f15c717b39fd17d
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
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ LineLength:
2
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - jruby
8
+ - rbx
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gem "rubysl", "~> 2.0", :platform => :rbx
2
+ # gem "rubysl", "~> 2.0", :platform => :rbx
3
3
  # Specify your gem's dependencies in rack-blogengine.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Rack Middleware to serve a simple blog
4
4
 
5
+ ## Build status
6
+
7
+ [![Build Status](https://travis-ci.org/Benny1992/rack-blogengine.png?branch=master)](https://travis-ci.org/Benny1992/rack-blogengine)
8
+
5
9
  ## Installation
6
10
 
7
11
  $ gem install rack-blogengine
data/Rakefile CHANGED
@@ -1,7 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
2
3
 
3
- require 'rspec/core/rake_task'
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
- RSpec::Core::RakeTask.new('spec')
6
-
7
- task :default => :spec
12
+ task :default => 'test:unit'
File without changes
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ #
2
+ # UserOperator Namespace
3
+ #
4
+ # @author [benny]
5
+ #
6
+ module UserOperator
7
+ # define your operators here
8
+ end
data/bin/rack-blogengine CHANGED
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
- require 'rack/blogengine/command_line_interface'
2
+ require 'rack/blogengine'
3
3
 
4
4
  if ARGV[0]
5
5
  command = ARGV[0].to_sym
6
6
  else
7
- command = "".to_sym
7
+ command = ''.to_sym
8
8
  end
9
9
 
10
10
  target = ARGV[1]
11
- target = "" if !ARGV[1]
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)
@@ -1,12 +1,19 @@
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/operator"
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
- module Blogengine
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
- if route
17
- return route["response"]
18
- else
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 target Target folder
11
+ # @param documents Documents which will be looked at
12
12
  # @return [Hash] route Hash {:path => "/foo", :response => [Array]}
13
- def self.map_route(env, documents)
14
- status = 200
15
- header = {"Content-Type" => "text/html; charset=UTF-8"}
16
- path = env["PATH_INFO"]
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
- return route_response
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
- return nil
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 "Available Commands are: \n\n"
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 #|| method == :setup || method == :getConfig
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
- unless target.empty?
26
- if target.include?("/")
27
- target = target.dup
28
- target["/"] = ""
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 = getConfig(targetfolder)
36
+ config = get_config(targetfolder)
36
37
 
37
38
  app = Rack::Builder.new do
38
- map "/assets" do
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["Usage"] == "yes"
47
- use Rack::Auth::Basic, "Protected Area" do |username, password|
48
- username == config["Username"] && password == config["Password"]
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.parseInDocuments(targetfolder)
55
+ $documents = DocParser.parse_in_documents(targetfolder)
55
56
 
56
57
  run Rack::Blogengine::Application
57
58
  end
58
59
 
59
- Rack::Server.start( :app => app, :Port => config["Port"], :server => config["Server"] )
60
+ Rack::Server.start(app: app, Port: config['Port'], server: config['Server'])
60
61
  else
61
- puts "Target is not a folder!"
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("operator.rb", "#{folder}/operator", true)
82
+ setup('operator.rb', "#{folder}/operator", true)
84
83
 
85
84
  # SET UP config.yml
86
- setup("config.yml", "#{folder}", true)
85
+ setup('config.yml', "#{folder}", true)
87
86
 
88
87
  # SET UP index.content
89
- setup("index.content", "#{folder}", true)
88
+ setup('index.content', "#{folder}", true)
90
89
 
91
90
  # SET UP layout.html
92
- setup("layout.html", "#{folder}/assets/layout", true)
91
+ setup('layout.html', "#{folder}/assets/layout", true)
93
92
 
94
93
  # SET UP style.css
95
- setup("style.css", "#{folder}/assets/style", false)
94
+ setup('style.css', "#{folder}/assets/style", false)
96
95
 
97
96
  # SET UP script.js
98
- setup("script.js", "#{folder}/assets/js", false)
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
- content = IO.read("#{::File.dirname(__FILE__)}/files/#{name}")
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 getConfig(target)
128
- configYAML = YAML::load(::File.open("#{target}/config.yml"))
127
+ def get_config(target)
128
+ config_yaml = YAML.load(::File.open("#{target}/config.yml"))
129
129
 
130
- port = configYAML["Port"]
131
- server = configYAML["Server"]
132
- username = configYAML["HTTPauth"]["username"].to_s.strip
133
- password = configYAML["HTTPauth"]["password"].to_s.strip
134
- usage = configYAML["HTTPauth"]["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
- config = {"Port" => port, "Server" => server, "Username" => username, "Password" => password, "Usage" => usage}
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.parseInDocuments(target)
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", "r")
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(".")[1]
24
- next if item == '.' or item == '..' or extension != "content"
25
-
26
- getFileContents(item)
27
- @html = fillFileContents(@layout)
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, so documents are available for operators (list all docs, etc...)
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
- documentshashed = documents.map do |document|
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.getFileContents(file)
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["/path"] = "/close"
60
- content["/title"] = "/close"
61
- content["/content"] = "/close"
62
- content["/date"] = "/close"
63
-
64
- contentarray = content.split("[/close]")
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? "[path]:"
68
- contentblock["[path]:"] = ""
66
+ if contentblock.include? '[path]:'
67
+ contentblock['[path]:'] = ''
69
68
  @path = "/#{contentblock}"
70
69
  end
71
70
 
72
- if contentblock.include? "[title]:"
73
- contentblock["[title]:"] = ""
71
+ if contentblock.include? '[title]:'
72
+ contentblock['[title]:'] = ''
74
73
  @title = contentblock.strip
75
74
  end
76
75
 
77
- if contentblock.include? "[content]:"
78
- contentblock["[content]:"] = ""
76
+ if contentblock.include? '[content]:'
77
+ contentblock['[content]:'] = ''
79
78
  @content = contentblock.strip
80
79
  end
81
80
 
82
- if contentblock.include? "[date]:"
83
- contentblock["[date]:"] = ""
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 = date.to_i
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.fillFileContents(layout)
96
+ def self.fill_file_contents(layout)
98
97
  html = layout.dup
99
98
 
100
- html.gsub! "{title}", @title
101
- html["{content}"] = @content
102
- html.gsub! "{date}", @date.strftime('%d.%m.%Y')
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
- return documents
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 == "@title" || var.to_s == "@date"
16
- hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
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["{% "+contentoperator.to_s+" %}"] = operatorhtml
28
+ @html['{% ' + contentoperator.to_s + ' %}'] = operatorhtml
29
29
  end
30
30
  end
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -0,0 +1,13 @@
1
+ module Rack
2
+ #
3
+ # BlogEngine Module used for namespacing
4
+ # Used in all /lib files
5
+ #
6
+ # @author [benny]
7
+ #
8
+ module Blogengine
9
+ def self.root
10
+ ::File.dirname(::File.dirname(::File.expand_path('../..', __FILE__)))
11
+ end
12
+ end
13
+ 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(".")[1]
11
- next if item == '.' or item == '..' or extension != "rb"
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
@@ -1,5 +1,11 @@
1
1
  module Rack
2
+ #
3
+ # BlogEngine Module used for namespacing
4
+ # Used in all /lib files
5
+ #
6
+ # @author [benny]
7
+ #
2
8
  module Blogengine
3
- VERSION = "0.2.0".freeze
9
+ VERSION = '0.2.1'.freeze
4
10
  end
5
11
  end
@@ -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
@@ -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.0
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
- date: 2014-01-22 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
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: '1.3'
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
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
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
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 2.0.0
55
- - !ruby/object:Gem::Dependency
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
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
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
- files:
77
- - ".gitignore"
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/files/config.yml
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
- homepage: ''
97
- licenses:
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
- require_paths:
120
+
121
+ require_paths:
103
122
  - lib
104
123
  - spec
105
- required_ruby_version: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- required_rubygems_version: !ruby/object:Gem::Requirement
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.0.rc.1
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
@@ -1,3 +0,0 @@
1
- module UserOperator
2
- #define your operators here
3
- end