rack-blogengine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad0a0f4e4702a31c490837832bef8fa0c96e2a2b
4
+ data.tar.gz: e61d6ab819d643afe7f0b467d090975e5d7c9690
5
+ SHA512:
6
+ metadata.gz: f71ba584675c2c82695f4cff9de09524a06d8f43322b8d778748c74ce08dcbfa4854a6bfeaa4be7b1408fa76069ab23fe57a5b01d8fc50207d8121d522c34965
7
+ data.tar.gz: 759821571f299483d17165b99b5194b8fa629a83e2bad677abf6f1e02b4b737b62d41efe75ac01a729f912362f98fd50027f44991aaa66d759c40bfd9d0019b5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-blogengine.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Benny1992
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Rack::Blogengine
2
+
3
+ Rack Middleware to serve a simple blog
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rack-blogengine'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rack-blogengine
18
+
19
+ ## Usage
20
+
21
+ Create a targetfolder where your Styling & Content is placed.
22
+
23
+ ### Structure
24
+
25
+ `targetfolder/layout` - save your layout.html and style.css in this folder
26
+
27
+ `targetfolder/images` - your images will be served from this folder (http://pathtoapp.tld/images)
28
+
29
+ `targetfolder/test.content` - your available blog entries matches to the .content files, each .content file is a blog entry
30
+
31
+ ### Layout
32
+
33
+ In the layout.html you use {title} and {content} which will then be populated with the values from each .content file
34
+ Example:
35
+ ```html
36
+ <!DOCTYPE html>
37
+ <html>
38
+ <head>
39
+ <title>{title}</title>
40
+ </head>
41
+ <body>
42
+ <h1>{title}</h1>
43
+ <div>
44
+ {content}
45
+ </div>
46
+ </body>
47
+ </html>
48
+ ```
49
+ ### Content
50
+
51
+ The Content files (.content) includes your content
52
+
53
+ `[path]` - this will be your access path to your blog entry
54
+
55
+ `[title]` - the title for your article
56
+
57
+ `[content]` - your content
58
+
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => :spec
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rack/blogengine'
3
+ require 'rack'
4
+
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
37
+
38
+
@@ -0,0 +1,15 @@
1
+ module Rack
2
+ module Blogengine
3
+ class Application
4
+ def self.call(env)
5
+ # Router for map docs to routes
6
+ route = ApplicationRouter.map_route(env, $targetfolder)
7
+ if route
8
+ return route["response"]
9
+ else
10
+ return [404, {"Content-Type" => "text/html; charset=UTF-8"}, ["Page not found"]]
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module Rack
2
+ module Blogengine
3
+ class ApplicationRouter
4
+ def self.map_route(env, target)
5
+ status = 200
6
+ header = {"Content-Type" => "text/html; charset=UTF-8"}
7
+ path = env["PATH_INFO"]
8
+
9
+ documents = DocParser.parseInDocuments(target)
10
+
11
+ # Iterate through available docs, if nothing matched return nil
12
+ documents.each do |doc|
13
+ if doc[:path] == path
14
+ route_response = {
15
+ "route" => path,
16
+ "response" => [status, header, [doc[:html]] ]
17
+ }
18
+
19
+ return route_response
20
+ end
21
+ end
22
+ return nil
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,69 @@
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...
12
+ def self.parseInDocuments(target)
13
+ @target = target
14
+ documents = []
15
+
16
+
17
+ stylesheet = ::File.open("#{@target}/layout/style.css", "r")
18
+ @css = stylesheet.read
19
+ documents << { path:"/style.css", html: @css }
20
+
21
+ layout_file = ::File.open("#{@target}/layout/layout.html", "r")
22
+ @html = layout_file.read
23
+
24
+ Dir.foreach("#{target}/") do |item|
25
+ extension = item.split(".")[1]
26
+ next if item == '.' or item == '..' or extension != "content"
27
+
28
+ getFileContents(item)
29
+ fillFileContents(@html)
30
+
31
+ @document = {path: @path, html: @html}
32
+ documents << @document
33
+ end
34
+
35
+ return documents
36
+ end
37
+
38
+ def self.getFileContents(file)
39
+ # do work on real items
40
+ content_file = ::File.open("#{@target}/#{file}");
41
+ content = content_file.read
42
+
43
+ contentarray = content.split(",")
44
+
45
+ contentarray.each do |contentblock|
46
+ if contentblock.include? "[path]:"
47
+ contentblock["[path]:"] = ""
48
+ @path = "/#{contentblock}"
49
+ end
50
+
51
+ if contentblock.include? "[title]:"
52
+ contentblock["[title]:"] = ""
53
+ @title = contentblock
54
+ end
55
+
56
+ if contentblock.include? "[content]:"
57
+ contentblock["[content]:"] = ""
58
+ @content = contentblock
59
+ end
60
+ end
61
+ end
62
+
63
+ def self.fillFileContents(layout)
64
+ layout.gsub! "{title}", @title
65
+ layout["{content}"] = @content
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module Blogengine
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "rack/blogengine/version"
2
+ require 'rack/blogengine/doc_parser'
3
+ require 'rack/blogengine/application'
4
+ require 'rack/blogengine/application_router'
5
+
6
+ module Rack
7
+ module Blogengine
8
+ end
9
+ end
10
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/blogengine/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-blogengine"
8
+ spec.version = Rack::Blogengine::VERSION
9
+ spec.authors = ["Benny1992"]
10
+ spec.email = ["klotz.benjamin@yahoo.de"]
11
+ spec.description = %q{Blogengine based on rack applications}
12
+ spec.summary = "#{spec.description}"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib", "spec"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", ">= 2.0.0"
24
+
25
+ spec.add_runtime_dependency "rack"
26
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-blogengine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Benny1992
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
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
+ type: :development
35
+ 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
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ type: :development
49
+ 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
+ name: rack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Blogengine based on rack applications
70
+ email:
71
+ - klotz.benjamin@yahoo.de
72
+ executables:
73
+ - rack-blogengine
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/rack-blogengine
83
+ - lib/rack/blogengine.rb
84
+ - lib/rack/blogengine/application.rb
85
+ - lib/rack/blogengine/application_router.rb
86
+ - lib/rack/blogengine/doc_parser.rb
87
+ - lib/rack/blogengine/version.rb
88
+ - rack-blogengine.gemspec
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ - spec
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.1.11
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Blogengine based on rack applications
114
+ test_files: []