rack-blogengine 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/README.md +28 -13
- data/lib/rack/blogengine/application.rb +2 -1
- data/lib/rack/blogengine/application_router.rb +2 -0
- data/lib/rack/blogengine/command_line_interface.rb +52 -33
- data/lib/rack/blogengine/doc_parser.rb +10 -7
- data/lib/rack/blogengine/files/config.yml +5 -1
- data/lib/rack/blogengine/version.rb +2 -2
- metadata +53 -67
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: ac2f380861a964dc372755134ec9ba579c01a518
|
4
|
+
data.tar.gz: a4eea9aa413b6fc8636168a37cf9d130d50c073e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4af90b6015da703e146f5932629858c22a20f76c97509a2a7d3ac52259c0b9aa54e4b59e41313acbbdee2ac66c48b94baa0c07ff033353d4b493397e25630080
|
7
|
+
data.tar.gz: c9dd2c8c09abdea19e83669aade5317f8263f14fedf23f33f31e4e0a879f77a5c8fb1fda60acadc5e4fce41c554e4f4c051dcb946db4db03ad38c9f81a227c28
|
data/README.md
CHANGED
@@ -4,33 +4,45 @@ Rack Middleware to serve a simple blog
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
$ gem install rack-blogengine
|
8
8
|
|
9
|
-
|
9
|
+
## Usage
|
10
10
|
|
11
|
-
|
11
|
+
`rack-blogengine generate <folder>` will create your Folder skeleton
|
12
12
|
|
13
|
-
|
13
|
+
### Structure
|
14
14
|
|
15
|
-
|
15
|
+
These folders and files will be created for you
|
16
16
|
|
17
|
-
|
17
|
+
#### Folders
|
18
|
+
`targetfolder/assets`
|
18
19
|
|
19
|
-
|
20
|
+
`targetfolder/assets/style`
|
20
21
|
|
21
|
-
`
|
22
|
+
`targetfolder/assets/js`
|
22
23
|
|
23
|
-
|
24
|
+
`targetfolder/assets/layout`
|
25
|
+
|
26
|
+
`targetfolder/assets/images`
|
27
|
+
|
28
|
+
`targetfolder/operator`
|
29
|
+
|
30
|
+
#### Files
|
31
|
+
`targetfolder/assets/style/style.css`
|
24
32
|
|
25
|
-
`targetfolder/
|
33
|
+
`targetfolder/assets/js/script.js`
|
26
34
|
|
27
|
-
`targetfolder/assets`
|
35
|
+
`targetfolder/assets/layout/layout.html` (filled with basic structure)
|
28
36
|
|
29
|
-
`targetfolder/
|
37
|
+
`targetfolder/index.content` (filled with dummy content)
|
38
|
+
|
39
|
+
`targetfolder/config.yml` (basic config setup - server: webrick, port: 3000)
|
40
|
+
|
41
|
+
`targetfolder/operator/operator.rb` (define your operator methods in module UserOperator)
|
30
42
|
|
31
43
|
### Layout
|
32
44
|
|
33
|
-
In the layout.html you use {title} and {
|
45
|
+
In the layout.html you use {title}, {content} and {date} which will then be populated with the values from each .content file
|
34
46
|
Example:
|
35
47
|
```html
|
36
48
|
<!DOCTYPE html>
|
@@ -41,6 +53,7 @@ Example:
|
|
41
53
|
<body>
|
42
54
|
<h1>{title}</h1>
|
43
55
|
<div>
|
56
|
+
{date}
|
44
57
|
{content}
|
45
58
|
</div>
|
46
59
|
</body>
|
@@ -54,6 +67,8 @@ The Content files (.content) includes your content
|
|
54
67
|
|
55
68
|
`[title][/title]` - the title for your article
|
56
69
|
|
70
|
+
`[date][/date]` - publishing date of your article
|
71
|
+
|
57
72
|
`[content][/content]` - your content
|
58
73
|
|
59
74
|
### Hint
|
@@ -11,6 +11,8 @@ module Rack
|
|
11
11
|
header = {"Content-Type" => "text/html; charset=UTF-8"}
|
12
12
|
path = env["PATH_INFO"]
|
13
13
|
|
14
|
+
# TODO: dont parse all docs on every request -> doc cache (maybe parse at rack-blogengine run)
|
15
|
+
# for fasten up accessing eg contentoperator in layout.html which has faraday request -> too big load times on every request!!!
|
14
16
|
documents = DocParser.parseInDocuments(target)
|
15
17
|
|
16
18
|
|
@@ -9,15 +9,14 @@ module Rack
|
|
9
9
|
puts "Command #{name} not available"
|
10
10
|
print "Available Commands are: \n\n"
|
11
11
|
self.class.instance_methods(false).each do |method|
|
12
|
-
print "\t #{method}\n" unless method == :method_missing
|
12
|
+
print "\t #{method}\n" unless method == :method_missing #|| method == :setup || method == :getConfig
|
13
13
|
end
|
14
14
|
print "\n"
|
15
15
|
end
|
16
16
|
|
17
|
-
# Method to run the
|
17
|
+
# Method to run the rack Application
|
18
18
|
# @param [String] target
|
19
19
|
def run(target)
|
20
|
-
|
21
20
|
unless target.empty?
|
22
21
|
if target.include?("/")
|
23
22
|
target = target.dup
|
@@ -28,22 +27,27 @@ module Rack
|
|
28
27
|
system("cd #{target}")
|
29
28
|
|
30
29
|
$targetfolder = "#{Dir.pwd}/#{target}"
|
31
|
-
config =
|
32
|
-
app = Rack::Builder.new do
|
33
|
-
use Rack::CommonLogger
|
34
|
-
use Rack::ShowExceptions
|
30
|
+
config = getConfig($targetfolder)
|
35
31
|
|
32
|
+
app = Rack::Builder.new do
|
36
33
|
map "/assets" do
|
37
34
|
run Rack::Directory.new("#{$targetfolder}/assets")
|
38
35
|
end
|
36
|
+
|
37
|
+
use Rack::CommonLogger
|
38
|
+
use Rack::ShowExceptions
|
39
39
|
use Rack::Lint
|
40
|
+
|
41
|
+
if config["Usage"] == "yes"
|
42
|
+
use Rack::Auth::Basic, "Protected Area" do |username, password|
|
43
|
+
username == config["Username"] && password == config["Password"]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
40
47
|
run Rack::Blogengine::Application
|
41
48
|
end
|
42
49
|
|
43
|
-
|
44
|
-
port = config["Port"];
|
45
|
-
server = config["Server"];
|
46
|
-
Rack::Server.start( :app => app, :Port => port, :server => server )
|
50
|
+
Rack::Server.start( :app => app, :Port => config["Port"], :server => config["Server"] )
|
47
51
|
else
|
48
52
|
puts "Target is not a folder!"
|
49
53
|
end
|
@@ -54,7 +58,6 @@ module Rack
|
|
54
58
|
|
55
59
|
# Command to generate the folder skeleton
|
56
60
|
# @param [String] folder
|
57
|
-
# TODO: refactor this - similar functions for each set up set => outsource to a method setup()
|
58
61
|
def generate(folder)
|
59
62
|
puts "\tGenerating folder skeleton\n"
|
60
63
|
system("mkdir #{folder}")
|
@@ -68,46 +71,62 @@ module Rack
|
|
68
71
|
puts "\n\tSetting up essential Files\n"
|
69
72
|
|
70
73
|
# SET UP operator.rb
|
71
|
-
|
72
|
-
system("touch #{folder}/operator/operator.rb")
|
73
|
-
content = IO.read("#{::File.dirname(__FILE__)}/files/operator.rb")
|
74
|
-
::File.open("#{folder}/operator/operator.rb", 'w') { |file| file.write(content) }
|
74
|
+
setup("operator.rb", "#{folder}/operator", true)
|
75
75
|
|
76
76
|
# SET UP config.yml
|
77
|
-
|
78
|
-
system("touch #{folder}/config.yml")
|
79
|
-
content = IO.read("#{::File.dirname(__FILE__)}/files/config.yml")
|
80
|
-
::File.open("#{folder}/config.yml", 'w') { |file| file.write(content) }
|
77
|
+
setup("config.yml", "#{folder}", true)
|
81
78
|
|
82
79
|
# SET UP index.content
|
83
|
-
|
84
|
-
system("touch #{folder}/index.content")
|
85
|
-
content = IO.read("#{::File.dirname(__FILE__)}/files/index.content")
|
86
|
-
::File.open("#{folder}/index.content", 'w') { |file| file.write(content) }
|
80
|
+
setup("index.content", "#{folder}", true)
|
87
81
|
|
88
82
|
# SET UP layout.html
|
89
|
-
|
90
|
-
system("touch #{folder}/assets/layout/layout.html")
|
91
|
-
content = IO.read("#{::File.dirname(__FILE__)}/files/layout.html")
|
92
|
-
::File.open("#{folder}/assets/layout/layout.html", 'w') { |file| file.write(content) }
|
83
|
+
setup("layout.html", "#{folder}/assets/layout", true)
|
93
84
|
|
94
85
|
# SET UP style.css
|
95
|
-
|
96
|
-
system("touch #{folder}/assets/style/style.css")
|
86
|
+
setup("style.css", "#{folder}/assets/style", false)
|
97
87
|
|
98
|
-
# SET UP
|
99
|
-
|
100
|
-
system("touch #{folder}/assets/js/script.js")
|
88
|
+
# SET UP script.js
|
89
|
+
setup("script.js", "#{folder}/assets/js", false)
|
101
90
|
|
102
91
|
puts "\n\tSetup finished! Have Fun\n"
|
103
92
|
puts "\tTo test it type rack-blogengine run #{folder}"
|
104
93
|
end
|
105
94
|
|
95
|
+
|
96
|
+
|
106
97
|
# Display Version
|
107
98
|
# return [String] VERSION
|
108
99
|
def version?
|
109
100
|
puts Rack::Blogengine::VERSION
|
110
101
|
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
# Helper method for generate to set up all essential files
|
106
|
+
# param [String] name
|
107
|
+
# param [String] path
|
108
|
+
# param [boolean] essential
|
109
|
+
def setup(name, path, essential)
|
110
|
+
puts "\tSet up #{path}/#{name}\n"
|
111
|
+
system("touch #{path}/#{name}")
|
112
|
+
if essential
|
113
|
+
content = IO.read("#{::File.dirname(__FILE__)}/files/#{name}")
|
114
|
+
::File.open("#{path}/#{name}", 'w') { |file| file.write(content) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Get YAML Config settings for Server.start && HTTPauth
|
119
|
+
def getConfig(target)
|
120
|
+
configYAML = YAML::load(::File.open("#{target}/config.yml"))
|
121
|
+
|
122
|
+
port = configYAML["Port"]
|
123
|
+
server = configYAML["Server"]
|
124
|
+
username = configYAML["HTTPauth"]["username"].to_s.strip
|
125
|
+
password = configYAML["HTTPauth"]["password"].to_s.strip
|
126
|
+
usage = configYAML["HTTPauth"]["usage"]
|
127
|
+
|
128
|
+
config = {"Port" => port, "Server" => server, "Username" => username, "Password" => password, "Usage" => usage}
|
129
|
+
end
|
111
130
|
end
|
112
131
|
end
|
113
132
|
end
|
@@ -73,22 +73,25 @@ module Rack
|
|
73
73
|
|
74
74
|
if contentblock.include? "[date]:"
|
75
75
|
contentblock["[date]:"] = ""
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
datearray = contentblock.split(",")
|
77
|
+
datearray = datearray.map do |date|
|
78
|
+
date = date.to_i
|
79
|
+
end
|
80
|
+
|
81
|
+
@date = Date.new(datearray[0], datearray[1], datearray[2])
|
79
82
|
end
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
# Replace layout placeholder with content from .content file
|
87
|
+
# @param [String] layout
|
88
|
+
# return [String] html placeholder replaced with content
|
86
89
|
def self.fillFileContents(layout)
|
87
90
|
html = layout.dup
|
88
91
|
|
89
92
|
html.gsub! "{title}", @title
|
90
93
|
html["{content}"] = @content
|
91
|
-
html.gsub! "{date}", @date
|
94
|
+
html.gsub! "{date}", @date.strftime('%d.%m.%Y')
|
92
95
|
|
93
96
|
return html
|
94
97
|
end
|
metadata
CHANGED
@@ -1,80 +1,66 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-blogengine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.8
|
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-01-15 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
14
16
|
name: bundler
|
15
|
-
|
16
|
-
requirements:
|
17
|
-
- -
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version:
|
17
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: "1.3"
|
20
22
|
type: :development
|
23
|
+
requirement: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
21
25
|
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
26
|
name: rake
|
29
|
-
|
30
|
-
requirements:
|
31
|
-
-
|
32
|
-
-
|
33
|
-
|
27
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- &id004
|
30
|
+
- ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: "0"
|
34
33
|
type: :development
|
34
|
+
requirement: *id002
|
35
|
+
- !ruby/object:Gem::Dependency
|
35
36
|
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
|
42
37
|
name: rspec
|
43
|
-
|
44
|
-
requirements:
|
38
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
45
40
|
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
41
|
+
- !ruby/object:Gem::Version
|
47
42
|
version: 2.0.0
|
48
43
|
type: :development
|
44
|
+
requirement: *id003
|
45
|
+
- !ruby/object:Gem::Dependency
|
49
46
|
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
|
56
47
|
name: rack
|
57
|
-
|
58
|
-
requirements:
|
59
|
-
-
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
48
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- *id004
|
62
51
|
type: :runtime
|
63
|
-
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
52
|
+
requirement: *id005
|
69
53
|
description: Blogengine based on rack applications
|
70
|
-
email:
|
54
|
+
email:
|
71
55
|
- klotz.benjamin@yahoo.de
|
72
|
-
executables:
|
56
|
+
executables:
|
73
57
|
- rack-blogengine
|
74
58
|
extensions: []
|
59
|
+
|
75
60
|
extra_rdoc_files: []
|
76
|
-
|
77
|
-
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
78
64
|
- Gemfile
|
79
65
|
- LICENSE.txt
|
80
66
|
- README.md
|
@@ -93,29 +79,29 @@ files:
|
|
93
79
|
- lib/rack/blogengine/operator.rb
|
94
80
|
- lib/rack/blogengine/version.rb
|
95
81
|
- rack-blogengine.gemspec
|
96
|
-
homepage:
|
97
|
-
licenses:
|
82
|
+
homepage: ""
|
83
|
+
licenses:
|
98
84
|
- MIT
|
99
85
|
metadata: {}
|
86
|
+
|
100
87
|
post_install_message:
|
101
88
|
rdoc_options: []
|
102
|
-
|
89
|
+
|
90
|
+
require_paths:
|
103
91
|
- lib
|
104
92
|
- 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'
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- *id004
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- *id004
|
115
99
|
requirements: []
|
100
|
+
|
116
101
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.2.0
|
102
|
+
rubygems_version: 2.2.0
|
118
103
|
signing_key:
|
119
104
|
specification_version: 4
|
120
105
|
summary: Blogengine based on rack applications
|
121
106
|
test_files: []
|
107
|
+
|