flatrack 1.0.0.alpha5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +1 -3
- data/Guardfile +11 -0
- data/README.md +41 -10
- data/Rakefile +8 -1
- data/bin/flatrack +1 -1
- data/flatrack.gemspec +30 -20
- data/lib/flatrack.rb +50 -7
- data/lib/flatrack/asset_extensions.rb +2 -4
- data/lib/flatrack/cli.rb +71 -20
- data/lib/flatrack/renderer.rb +18 -7
- data/lib/flatrack/renderer/base.rb +2 -4
- data/lib/flatrack/request.rb +6 -14
- data/lib/flatrack/response.rb +19 -32
- data/lib/flatrack/response/view_context.rb +27 -40
- data/lib/flatrack/site.rb +27 -9
- data/lib/flatrack/version.rb +2 -2
- data/lib/rake/asset_tasks.rb +12 -12
- data/logo.png +0 -0
- data/public/assets/manifest-6d7e78baa6d2c0670a82be957315fcbc.json +1 -0
- data/renderers/erb.rb +1 -3
- data/renderers/html.rb +1 -3
- data/renderers/rb.rb +11 -9
- data/spec/fixtures/assets/application.js.coffee +2 -0
- data/spec/lib/flatrack/asset_extensions_spec.rb +13 -0
- data/spec/lib/flatrack/cli_spec.rb +58 -0
- data/spec/lib/flatrack/renderer/base_spec.rb +4 -0
- data/spec/lib/flatrack/renderer_spec.rb +4 -0
- data/spec/lib/flatrack/request_spec.rb +22 -0
- data/spec/lib/flatrack/response/view_context_spec.rb +76 -0
- data/spec/lib/flatrack/response_spec.rb +22 -0
- data/spec/lib/flatrack/site_spec.rb +39 -0
- data/spec/lib/flatrack_spec.rb +28 -0
- data/spec/lib/rake/asset_tasks_spec.rb +55 -0
- data/spec/renderers/erb_spec.rb +21 -0
- data/spec/renderers/html_spec.rb +21 -0
- data/spec/renderers/rb_spec.rb +21 -0
- data/spec/spec_helper.rb +14 -2
- data/spec/support/site_helper.rb +52 -0
- data/templates/.gitignore +2 -1
- data/{spec/rake/asset_tasks_spec.rb → templates/.keep} +0 -0
- data/templates/404.html +1 -0
- data/templates/500.html +1 -0
- data/templates/Rakefile +1 -1
- data/templates/boot.rb +3 -1
- data/templates/javascript.js.coffee +2 -0
- data/templates/layout.html.erb +5 -3
- data/templates/stylesheet.css.scss +2 -0
- metadata +163 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02f38974206178dab428bdc7d4b7a0c2aa92dc03
|
4
|
+
data.tar.gz: b6b70a1a6ea5ddd2a9a4c344c547228715d499c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a2cd97cdcdcd578d7a3af3278ef743c7fbd838eb1d195e7233e406c4cf9a74d0a26c932852fc4c04cf402cdb2a3f55af753911487325de9cfdf6d11c6e32888
|
7
|
+
data.tar.gz: 22a927232f2f038a3297ef20e78dd5a605950a032ec411b5cb8796720c461a7faefd9be9c152518f25f345c58c1c2c52d12c2ddda12bcbe9363213ff82f5d3f7
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
guard :bundler do
|
2
|
+
watch('Gemfile')
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
7
|
+
watch(%r{^spec/.+_spec\.rb$})
|
8
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
9
|
+
watch(%r{^renderers/(.+)\.rb$}) { |m| "spec/renderers/#{m[1]}_spec.rb" }
|
10
|
+
watch('spec/spec_helper.rb') { "spec" }
|
11
|
+
end
|
data/README.md
CHANGED
@@ -1,24 +1,55 @@
|
|
1
|
-
|
1
|
+
![Flatrack](https://raw.github.com/jwaldrip/flatrack/master/logo.png)
|
2
|
+
--
|
2
3
|
|
3
|
-
|
4
|
+
[![Version](http://allthebadges.io/jwaldrip/flatrack/badge_fury.png)](http://allthebadges.io/jwaldrip/flatrack/badge_fury)
|
5
|
+
[![Dependencies](http://allthebadges.io/jwaldrip/flatrack/gemnasium.png)](http://allthebadges.io/jwaldrip/flatrack/gemnasium)
|
6
|
+
[![Build Status](http://allthebadges.io/jwaldrip/flatrack/travis.png?1)](http://allthebadges.io/jwaldrip/flatrack/travis)
|
7
|
+
[![Coverage](http://allthebadges.io/jwaldrip/flatrack/coveralls.png)](http://allthebadges.io/jwaldrip/flatrack/coveralls)
|
8
|
+
[![Code Climate](http://allthebadges.io/jwaldrip/flatrack/code_climate.png)](http://allthebadges.io/jwaldrip/flatrack/code_climate)
|
9
|
+
|
10
|
+
## About
|
11
|
+
A simple rack web layer for delivering rendered static files.
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
7
|
-
|
15
|
+
$ gem install flatrack
|
16
|
+
|
17
|
+
## Creating your Flatrack site
|
18
|
+
|
19
|
+
$ flatrack new my-website
|
20
|
+
|
21
|
+
### Structure
|
22
|
+
|
23
|
+
You should have 3 directories:
|
8
24
|
|
9
|
-
|
25
|
+
- assets
|
26
|
+
- layouts
|
27
|
+
- pages
|
28
|
+
|
29
|
+
#### Assets
|
30
|
+
Location of sprockets assets, flatrack comes with Sass and Coffeescript out of the box.
|
10
31
|
|
11
|
-
|
32
|
+
- images
|
33
|
+
- javascripte
|
34
|
+
- stylesheets
|
35
|
+
|
36
|
+
#### Pages
|
37
|
+
Pages are the guts of your site, this is what your users will ultimately see. Basically put your content here.
|
12
38
|
|
13
|
-
|
39
|
+
#### Layouts
|
40
|
+
Layouts are the skin of your site, it's what takes all those guts that your users need and crave and puts them in a nice pretty layout for them to enjoy.
|
41
|
+
|
42
|
+
## Running your site
|
14
43
|
|
15
|
-
|
44
|
+
$ flatrack start
|
45
|
+
|
46
|
+
## How it works
|
16
47
|
|
17
|
-
|
48
|
+
Anything in `/pages` maps to a URL at `/`, root of a directory will always map to the `index.html.*` file in it.
|
18
49
|
|
19
|
-
|
50
|
+
**for example**
|
20
51
|
|
21
|
-
|
52
|
+
`GET /foo.html` would map to `/pages/foo.html.erb`, the erb (or any other format) is optional if you wish to render your pages dynamically.
|
22
53
|
|
23
54
|
## Contributing
|
24
55
|
|
data/Rakefile
CHANGED
data/bin/flatrack
CHANGED
data/flatrack.gemspec
CHANGED
@@ -6,34 +6,44 @@ require 'flatrack/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
|
8
8
|
# Information
|
9
|
-
spec.name
|
10
|
-
spec.version
|
11
|
-
spec.authors
|
12
|
-
spec.email
|
13
|
-
spec.summary
|
14
|
-
spec.
|
15
|
-
|
9
|
+
spec.name = "flatrack"
|
10
|
+
spec.version = Flatrack::VERSION
|
11
|
+
spec.authors = ["Jason Waldrip"]
|
12
|
+
spec.email = ["jason@waldrip.net"]
|
13
|
+
spec.summary = 'Deliver static files with style.'
|
14
|
+
spec.description = <<-description
|
15
|
+
A rack based static site builder with templates, layouts and project structure
|
16
|
+
based routing.
|
17
|
+
|
18
|
+
description
|
19
|
+
spec.homepage = "https://github.com/jwaldrip/flatrack"
|
20
|
+
spec.license = "MIT"
|
16
21
|
|
17
22
|
# Files
|
18
|
-
spec.files
|
19
|
-
spec.executables
|
20
|
-
spec.test_files
|
21
|
-
spec.require_paths
|
23
|
+
spec.files = `git ls-files`.split($/)
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
+
spec.require_paths = ["lib"]
|
22
27
|
|
23
28
|
# Ruby Version
|
24
29
|
spec.required_ruby_version = '>= 1.9.3'
|
25
30
|
|
26
31
|
# Dependencies
|
27
|
-
spec.
|
28
|
-
spec.
|
29
|
-
spec.
|
30
|
-
spec.
|
31
|
-
spec.
|
32
|
-
spec.
|
33
|
-
spec.
|
34
|
-
spec.add_dependency 'rake'
|
32
|
+
spec.add_runtime_dependency 'rack', '~> 1.4'
|
33
|
+
spec.add_runtime_dependency 'activesupport', '~> 3.2'
|
34
|
+
spec.add_runtime_dependency 'sass', '~> 3.2'
|
35
|
+
spec.add_runtime_dependency 'sprockets-sass', '~> 1.0'
|
36
|
+
spec.add_runtime_dependency 'thor', '~> 0.18'
|
37
|
+
spec.add_runtime_dependency 'coffee-script', '~> 2.2'
|
38
|
+
spec.add_runtime_dependency 'rake', '~> 0.8'
|
35
39
|
|
36
40
|
# Dev Dependencies
|
37
41
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
38
|
-
spec.add_development_dependency 'rspec'
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0.beta'
|
43
|
+
spec.add_development_dependency 'guard', '~> 2.5'
|
44
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.2'
|
45
|
+
spec.add_development_dependency 'guard-bundler', '~> 2.0'
|
46
|
+
spec.add_development_dependency 'pry', '~> 0.9.12.6'
|
47
|
+
spec.add_development_dependency 'coveralls', '~> 0.7.0'
|
48
|
+
spec.add_development_dependency 'simplecov', '~> 0.8.2'
|
39
49
|
end
|
data/lib/flatrack.rb
CHANGED
@@ -3,8 +3,9 @@ require 'active_support/all'
|
|
3
3
|
require 'sprockets'
|
4
4
|
require 'sprockets-sass'
|
5
5
|
require 'sass'
|
6
|
+
require 'rack'
|
6
7
|
|
7
|
-
|
8
|
+
class Flatrack
|
8
9
|
extend ActiveSupport::Autoload
|
9
10
|
|
10
11
|
autoload :Renderer
|
@@ -19,15 +20,39 @@ module Flatrack
|
|
19
20
|
|
20
21
|
FORMATS = {}
|
21
22
|
|
22
|
-
|
23
|
+
delegate :gem_root, :site_root, to: self
|
24
|
+
|
25
|
+
def self.gem_root
|
23
26
|
File.expand_path File.join __FILE__, '..'
|
24
27
|
end
|
25
28
|
|
26
|
-
def self.
|
27
|
-
|
29
|
+
def self.site_root
|
30
|
+
File.expand_path Dir.pwd
|
31
|
+
end
|
32
|
+
|
33
|
+
class << self
|
34
|
+
|
35
|
+
def delegate_instance
|
36
|
+
@delegate_instance ||= new
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset!
|
40
|
+
@delegate_instance = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def method_missing(m, *args, &block)
|
46
|
+
delegate_instance.public_method(m).call(*args, &block)
|
47
|
+
end
|
48
|
+
|
28
49
|
end
|
29
50
|
|
30
|
-
def
|
51
|
+
def config(&block)
|
52
|
+
yield self
|
53
|
+
end
|
54
|
+
|
55
|
+
def assets
|
31
56
|
@assets ||= begin
|
32
57
|
Sprockets::Environment.new.tap do |environment|
|
33
58
|
environment.append_path 'assets/images'
|
@@ -38,8 +63,26 @@ module Flatrack
|
|
38
63
|
end
|
39
64
|
end
|
40
65
|
|
41
|
-
|
66
|
+
def register_format(ext, mime)
|
67
|
+
FORMATS[ext.to_s] = mime
|
68
|
+
end
|
69
|
+
|
70
|
+
def middleware
|
71
|
+
@middleware ||= []
|
72
|
+
end
|
73
|
+
|
74
|
+
def use(*args)
|
75
|
+
middleware << args
|
76
|
+
end
|
42
77
|
|
43
|
-
|
78
|
+
# By default we know how to render 'text/html'
|
79
|
+
register_format :html, 'text/html'
|
44
80
|
|
81
|
+
# Fix Locales issue
|
82
|
+
I18n.enforce_available_locales = false
|
83
|
+
|
84
|
+
# Load all renderers
|
85
|
+
Dir.glob(File.join gem_root, '../renderers/**/*.rb').each do |f|
|
86
|
+
require f
|
87
|
+
end
|
45
88
|
end
|
data/lib/flatrack/cli.rb
CHANGED
@@ -1,32 +1,83 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'flatrack'
|
2
3
|
|
3
|
-
|
4
|
+
class Flatrack
|
4
5
|
class CLI < Thor
|
5
6
|
include FileUtils
|
6
7
|
include Thor::Actions
|
7
8
|
|
9
|
+
source_root File.join Flatrack.gem_root, '..', 'templates'
|
10
|
+
|
11
|
+
method_option :verbose, type: :boolean, default: true, aliases: :v
|
12
|
+
method_option :bundle, type: :boolean, default: true, aliases: :b
|
13
|
+
|
8
14
|
desc 'new NAME', 'create a new flatrack site with the given name'
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
16
|
+
KEEP_DIRS = [
|
17
|
+
'assets/stylesheets',
|
18
|
+
'assets/javascripts',
|
19
|
+
'assets/images',
|
20
|
+
'pages',
|
21
|
+
'layouts'
|
22
|
+
]
|
23
|
+
|
24
|
+
FILES = {
|
25
|
+
'.gitignore' => '.gitignore',
|
26
|
+
'boot.rb' => 'boot.rb',
|
27
|
+
'Rakefile' => 'Rakefile',
|
28
|
+
'Gemfile.erb' => 'Gemfile',
|
29
|
+
'config.ru' => 'config.ru',
|
30
|
+
'layout.html.erb' => 'layouts/layout.html.erb',
|
31
|
+
'page.html.erb' => 'pages/index.html.erb',
|
32
|
+
'stylesheet.css.scss' => 'assets/stylesheets/main.css.scss',
|
33
|
+
'javascript.js.coffee' => 'assets/javascripts/main.js.coffee'
|
34
|
+
}
|
35
|
+
|
36
|
+
def new(path)
|
37
|
+
mkdir_p path
|
38
|
+
full_path = File.expand_path path
|
39
|
+
@name = File.basename(full_path).titleize
|
40
|
+
self.destination_root = full_path
|
41
|
+
write_keeps
|
42
|
+
write_files
|
43
|
+
bundle!
|
44
|
+
end
|
45
|
+
|
46
|
+
method_option :verbose, type: :boolean, default: true, aliases: :v
|
47
|
+
method_option :port, type: :numeric, default: 5959, aliases: :p
|
48
|
+
|
49
|
+
desc 'start PORT', 'run the site on the given port'
|
50
|
+
|
51
|
+
def start
|
52
|
+
require './boot'
|
53
|
+
run_opts = {}
|
54
|
+
run_opts[:app] = Flatrack::Site
|
55
|
+
run_opts[:Port] = options[:port]
|
56
|
+
run_opts[:Logger] = Logger.new('/dev/null') unless options[:verbose]
|
57
|
+
run_opts[:AccessLog] = Logger.new('/dev/null') unless options[:verbose]
|
58
|
+
Rack::Server.start run_opts
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def bundle!
|
64
|
+
Dir.chdir(destination_root) do
|
65
|
+
cmd = 'bundle install'
|
66
|
+
cmd << ' --quiet' unless options[:verbose]
|
67
|
+
system cmd
|
68
|
+
end if options[:bundle]
|
69
|
+
end
|
70
|
+
|
71
|
+
def write_keeps
|
72
|
+
KEEP_DIRS.each do |dir|
|
73
|
+
template '.keep', File.join(dir, '.keep'), verbose: options[:verbose]
|
28
74
|
end
|
29
75
|
end
|
30
76
|
|
77
|
+
def write_files
|
78
|
+
FILES.each do |temp, dest|
|
79
|
+
template temp, dest, verbose: options[:verbose]
|
80
|
+
end
|
81
|
+
end
|
31
82
|
end
|
32
|
-
end
|
83
|
+
end
|
data/lib/flatrack/renderer.rb
CHANGED
@@ -1,20 +1,31 @@
|
|
1
|
-
|
1
|
+
class Flatrack
|
2
2
|
module Renderer
|
3
|
-
extend self
|
4
3
|
extend ActiveSupport::Autoload
|
5
4
|
|
6
5
|
autoload :Base
|
7
6
|
|
8
7
|
def find(file)
|
9
|
-
template =
|
10
|
-
|
8
|
+
template = File.exists?(file) ? file : [*pages(file), *layouts(file)][0]
|
9
|
+
fail FileNotFound, "could not find #{file}" unless template
|
11
10
|
ext = File.extname(template).sub(/\./, '')
|
12
11
|
|
13
|
-
renderer = Base.descendants.find
|
14
|
-
|
12
|
+
renderer = Base.descendants.find do |descendant|
|
13
|
+
descendant.renders?(ext)
|
14
|
+
end || fail(RendererNotFound, "could not find a renderer for #{file}")
|
15
15
|
|
16
16
|
renderer.new template
|
17
17
|
end
|
18
18
|
|
19
|
+
private
|
20
|
+
|
21
|
+
def pages(file)
|
22
|
+
Dir[File.join 'pages', "#{file}*"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def layouts(file)
|
26
|
+
Dir[File.join 'layouts', "#{file}*"]
|
27
|
+
end
|
28
|
+
|
29
|
+
module_function :find, :pages, :layouts
|
19
30
|
end
|
20
|
-
end
|
31
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
|
1
|
+
class Flatrack
|
2
2
|
module Renderer
|
3
3
|
class Base
|
4
|
-
|
5
4
|
attr_reader :contents
|
6
5
|
|
7
6
|
def self.renders(ext = nil)
|
@@ -15,7 +14,6 @@ module Flatrack
|
|
15
14
|
def initialize(file)
|
16
15
|
@contents = File.read file
|
17
16
|
end
|
18
|
-
|
19
17
|
end
|
20
18
|
end
|
21
|
-
end
|
19
|
+
end
|