sharpie 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/README.md +9 -2
- data/lib/sharpie/version.rb +1 -1
- data/lib/sharpie.rb +0 -4
- metadata +4 -4
- data/lib/sharpie/sinatra_static.rb +0 -86
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/sharpie.png)](http://badge.fury.io/rb/sharpie)
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/adelevie/sharpie.png)](https://codeclimate.com/github/adelevie/sharpie)
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/adelevie/sharpie.png)](https://travis-ci.org/adelevie/sharpie)
|
6
|
+
|
7
|
+
|
1
8
|
# Sharpie
|
2
9
|
|
3
10
|
Quick and easy static site generation with a familiar API.
|
@@ -93,11 +100,11 @@ Sinatra routes make web app and API creation dead-simple. The syntax is straight
|
|
93
100
|
|
94
101
|
### Why not Jekyll?
|
95
102
|
|
96
|
-
Jekyll is great for blogs and other types of sites where content is "hand created." That is, a human creates a file in a folder and writes some Markdown. Sharpie is more geared towards use-cases where the original content is already in a machine-readable format. For example, if you have a
|
103
|
+
Jekyll is great for blogs and other types of sites where content is "hand created." That is, a human creates a file in a folder and writes some Markdown. Sharpie is more geared towards use-cases where the original content is already in a machine-readable format. For example, if you have a database whose contents you want to expose via REST API. You also don't want to maintain a server and you don't want to worry about scaline. With Sharpie, you can write such an API with very few (yet straightfoward) lines of code.
|
97
104
|
|
98
105
|
### Fork
|
99
106
|
|
100
|
-
This software is mostly a fork of the [sinatra-static](https://github.com/paulasmuth/sinatra-static) gem by [Paul Asmuth](https://twitter.com/paulasmuth). Paul's code is very well-written. I'd rather copy and attribute it than re-invent a well-made wheel
|
107
|
+
This software is mostly a fork of the [sinatra-static](https://github.com/paulasmuth/sinatra-static) gem by [Paul Asmuth](https://twitter.com/paulasmuth). Paul's code is very well-written. I'd rather copy and attribute it than re-invent a well-made wheel. I'm focusing on building an interface that suits my needs. More specifically, I want Sharpie to be part of a toolchain for rapidly developing static file-backed REST APIs.
|
101
108
|
|
102
109
|
# License
|
103
110
|
|
data/lib/sharpie/version.rb
CHANGED
data/lib/sharpie.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sharpie
|
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:
|
@@ -115,12 +115,12 @@ extensions: []
|
|
115
115
|
extra_rdoc_files: []
|
116
116
|
files:
|
117
117
|
- .gitignore
|
118
|
+
- .travis.yml
|
118
119
|
- Gemfile
|
119
120
|
- LICENSE.txt
|
120
121
|
- README.md
|
121
122
|
- Rakefile
|
122
123
|
- lib/sharpie.rb
|
123
|
-
- lib/sharpie/sinatra_static.rb
|
124
124
|
- lib/sharpie/version.rb
|
125
125
|
- sharpie.gemspec
|
126
126
|
- test/helper.rb
|
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
segments:
|
145
145
|
- 0
|
146
|
-
hash:
|
146
|
+
hash: 95835372314545834
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
segments:
|
154
154
|
- 0
|
155
|
-
hash:
|
155
|
+
hash: 95835372314545834
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
158
|
rubygems_version: 1.8.24
|
@@ -1,86 +0,0 @@
|
|
1
|
-
class SinatraStatic
|
2
|
-
|
3
|
-
@@file_extensions = %w(css js xml json html csv)
|
4
|
-
|
5
|
-
attr_accessor :app
|
6
|
-
|
7
|
-
include Rack::Test::Methods
|
8
|
-
|
9
|
-
require 'term/ansicolor'
|
10
|
-
class ColorString < String
|
11
|
-
include Term::ANSIColor
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(app)
|
15
|
-
@app = app
|
16
|
-
end
|
17
|
-
|
18
|
-
def build!(dir)
|
19
|
-
handle_error_no_each_route! unless @app.respond_to?(:each_route)
|
20
|
-
handle_error_dir_not_found!(dir) unless dir_exists?(dir)
|
21
|
-
build_routes(dir)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def build_routes(dir)
|
27
|
-
@app.each_route do |route|
|
28
|
-
next unless route.verb == 'GET'
|
29
|
-
build_path(route.path, dir)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def build_path(path, dir)
|
34
|
-
::FileUtils.mkdir_p(dir_for_path(path, dir))
|
35
|
-
::File.open(file_for_path(path, dir), 'w+') do |f|
|
36
|
-
f.write(get_path(path).body)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def get_path(path)
|
41
|
-
self.get(path).tap do |resp|
|
42
|
-
handle_error_non_200!(path) unless resp.status == 200
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def file_for_path(path, dir)
|
47
|
-
if path.match(/[^\/\.]+.(#{file_extensions.join("|")})$/)
|
48
|
-
::File.join(dir, path)
|
49
|
-
else
|
50
|
-
::File.join(dir, path, 'index.html')
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def dir_exists?(dir)
|
55
|
-
::File.exists?(dir) && ::File.directory?(dir)
|
56
|
-
end
|
57
|
-
|
58
|
-
def dir_for_path(path, dir)
|
59
|
-
file_for_path(path, dir).match(/(.*)\/[^\/]+$/)[1]
|
60
|
-
end
|
61
|
-
|
62
|
-
def file_extensions
|
63
|
-
@@file_extensions
|
64
|
-
end
|
65
|
-
|
66
|
-
def env
|
67
|
-
ENV['RACK_ENV']
|
68
|
-
end
|
69
|
-
|
70
|
-
def handle_error_no_each_route!
|
71
|
-
handle_error!("can't call app.each_route, did you include sinatra-advanced-routes?")
|
72
|
-
end
|
73
|
-
|
74
|
-
def handle_error_dir_not_found!(dir)
|
75
|
-
handle_error!("can't find output directory: #{dir}")
|
76
|
-
end
|
77
|
-
|
78
|
-
def handle_error_non_200!(path)
|
79
|
-
handle_error!("GET #{path} returned non-200 status code...")
|
80
|
-
end
|
81
|
-
|
82
|
-
def handle_error!(desc)
|
83
|
-
puts ColorString.new("failed: #{desc}").red; exit!
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|