guinness 0.0.1 → 0.0.2
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.
- data/bin/guinness +26 -0
- data/lib/guinness/application.rb +41 -0
- data/lib/guinness/server.rb +27 -0
- data/lib/guinness/version.rb +1 -1
- data/lib/guinness/view.rb +30 -0
- data/lib/guinness.rb +4 -1
- metadata +9 -26
- data/.gitignore +0 -24
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.md +0 -29
- data/Rakefile +0 -1
- data/guinness.gemspec +0 -26
data/bin/guinness
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/guinness', __FILE__)
|
4
|
+
|
5
|
+
cmd = ARGV[0] || 'drink'
|
6
|
+
dir = ARGV[1] || '_source'
|
7
|
+
puts "#{Guinness::EMOJI} Guinness : App root is: '#{dir}'"
|
8
|
+
|
9
|
+
case cmd
|
10
|
+
|
11
|
+
when 'new'
|
12
|
+
require 'fileutils'
|
13
|
+
File.open(File.join(FileUtils.mkpath(dir), 'index.html'), 'w') do |f|
|
14
|
+
f.puts 'Cheers from Guinness!'
|
15
|
+
end
|
16
|
+
|
17
|
+
when 'build', 'drink'
|
18
|
+
abort "#{Guinness::EMOJI} Guinness : Unable to locate: '#{dir}'" unless Dir.exists?(dir)
|
19
|
+
@app = Guinness::Application.new(root: dir)
|
20
|
+
@app.send cmd
|
21
|
+
|
22
|
+
else
|
23
|
+
puts "'#{cmd}' is not a valid guinness command"
|
24
|
+
puts 'Usage: guinness (build,drink,new) <directory>'
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Guinness::Application
|
2
|
+
|
3
|
+
attr_accessor :settings, :builder
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@settings = { output_dir: '../' }.merge options
|
7
|
+
|
8
|
+
app = self
|
9
|
+
@builder = Rack::Builder.new do
|
10
|
+
use Rack::CommonLogger
|
11
|
+
use Rack::ShowStatus # Nice looking 404s and other messages
|
12
|
+
use Rack::ShowExceptions # Nice looking errors
|
13
|
+
run Guinness::Server.new app
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def drink
|
18
|
+
Rack::Handler::Thin.run @builder, Port: 9393
|
19
|
+
end
|
20
|
+
|
21
|
+
def build
|
22
|
+
FileUtils.cd @settings[:root] do
|
23
|
+
# collect all files that don't start with '_'
|
24
|
+
files = Dir[File.join('**', '*')].reject { |f| f =~ /(^_|\/_)/ }
|
25
|
+
|
26
|
+
files.each do |file|
|
27
|
+
path = File.join @settings[:output_dir], file
|
28
|
+
|
29
|
+
if Tilt[path]
|
30
|
+
body = Guinness::View.new(file).render
|
31
|
+
File.open(path.chomp(File.extname(path)), 'w') { |f| f.write body }
|
32
|
+
elsif Dir.exists? file
|
33
|
+
FileUtils.mkpath path
|
34
|
+
else
|
35
|
+
FileUtils.cp file, path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Guinness::Server
|
2
|
+
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
body = render File.join(@app.settings[:root], env['PATH_INFO'])
|
9
|
+
if body
|
10
|
+
[200, { 'Content-Type' => Rack::Mime.mime_type(File.extname(env['PATH_INFO']), 'text/html') }, [body]]
|
11
|
+
else
|
12
|
+
[404, { 'Content-Type' => 'text/plain' }, 'Not Found']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def render(path)
|
17
|
+
return File.read path if File.file? path
|
18
|
+
|
19
|
+
# default to index if path to directory
|
20
|
+
path = File.join(path, 'index') if Dir.exists? path
|
21
|
+
|
22
|
+
# return the first filename that matches file
|
23
|
+
template = Dir[File.join("#{path}*")].first
|
24
|
+
return Guinness::View.new(template).render if template
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/guinness/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
class Guinness::View
|
2
|
+
|
3
|
+
def initialize(template)
|
4
|
+
@template = template
|
5
|
+
end
|
6
|
+
|
7
|
+
def partial(path, locals = {})
|
8
|
+
filepath = File.join File.dirname(@template), path.to_s
|
9
|
+
# insert a '_' before the filename before we search
|
10
|
+
_partial = Dir["#{filepath.sub(/\/(?!.*\/)/, '/_')}*"].first
|
11
|
+
|
12
|
+
if _partial
|
13
|
+
Tilt.new(_partial).render(self, locals)
|
14
|
+
else
|
15
|
+
raise "#{Guinness::EMOJI} Guinness : Unable to locate partial at: '#{filepath}'"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# return a view body or nil if adequate template cannot be found
|
20
|
+
def render
|
21
|
+
template_body = Tilt.new(@template).render(self)
|
22
|
+
if @layout
|
23
|
+
layout = Dir[File.join(File.dirname(@template), @layout) + '*'].first
|
24
|
+
raise "#{Guinness::EMOJI} Guinness : Unable to locate layout at: '#{@layout}'" unless layout
|
25
|
+
@body = Tilt.new(layout).render(self) { template_body }
|
26
|
+
end
|
27
|
+
@body || template_body
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/guinness.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guinness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: haml
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
- !ruby/object:Gem::Dependency
|
63
47
|
name: rake
|
64
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,21 +75,20 @@ dependencies:
|
|
91
75
|
- - ! '>='
|
92
76
|
- !ruby/object:Gem::Version
|
93
77
|
version: '0'
|
94
|
-
description: Guinness is a micro framework for building static websites.
|
78
|
+
description: ! 'Guinness is a micro framework for building static websites. '
|
95
79
|
email:
|
96
80
|
- rbmrclo@hotmail.com
|
97
|
-
executables:
|
81
|
+
executables:
|
82
|
+
- guinness
|
98
83
|
extensions: []
|
99
84
|
extra_rdoc_files: []
|
100
85
|
files:
|
101
|
-
-
|
102
|
-
-
|
103
|
-
-
|
104
|
-
- README.md
|
105
|
-
- Rakefile
|
106
|
-
- guinness.gemspec
|
107
|
-
- lib/guinness.rb
|
86
|
+
- bin/guinness
|
87
|
+
- lib/guinness/application.rb
|
88
|
+
- lib/guinness/server.rb
|
108
89
|
- lib/guinness/version.rb
|
90
|
+
- lib/guinness/view.rb
|
91
|
+
- lib/guinness.rb
|
109
92
|
homepage: ''
|
110
93
|
licenses:
|
111
94
|
- MIT
|
data/.gitignore
DELETED
@@ -1,24 +0,0 @@
|
|
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
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
23
|
-
*.un~
|
24
|
-
*.DS_Store
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Robbie Marcelo
|
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
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Guinness
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'guinness'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install guinness
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it ( https://github.com/[my-github-username]/guinness/fork )
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create a new Pull Request
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/guinness.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'guinness/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "guinness"
|
8
|
-
spec.version = Guinness::VERSION
|
9
|
-
spec.authors = ["Robbie Marcelo"]
|
10
|
-
spec.email = ["rbmrclo@hotmail.com"]
|
11
|
-
spec.summary = %q{Guinness is a micro framework for building static websites. }
|
12
|
-
spec.description = %q{Guinness is a micro framework for building static websites.}
|
13
|
-
spec.homepage = ""
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
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"]
|
20
|
-
|
21
|
-
spec.add_dependency 'rack'
|
22
|
-
spec.add_dependency 'tilt'
|
23
|
-
spec.add_development_dependency 'haml'
|
24
|
-
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
end
|