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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -1
  3. data/.rubocop.yml +6 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +5 -0
  6. data/Gemfile +1 -3
  7. data/Guardfile +11 -0
  8. data/README.md +41 -10
  9. data/Rakefile +8 -1
  10. data/bin/flatrack +1 -1
  11. data/flatrack.gemspec +30 -20
  12. data/lib/flatrack.rb +50 -7
  13. data/lib/flatrack/asset_extensions.rb +2 -4
  14. data/lib/flatrack/cli.rb +71 -20
  15. data/lib/flatrack/renderer.rb +18 -7
  16. data/lib/flatrack/renderer/base.rb +2 -4
  17. data/lib/flatrack/request.rb +6 -14
  18. data/lib/flatrack/response.rb +19 -32
  19. data/lib/flatrack/response/view_context.rb +27 -40
  20. data/lib/flatrack/site.rb +27 -9
  21. data/lib/flatrack/version.rb +2 -2
  22. data/lib/rake/asset_tasks.rb +12 -12
  23. data/logo.png +0 -0
  24. data/public/assets/manifest-6d7e78baa6d2c0670a82be957315fcbc.json +1 -0
  25. data/renderers/erb.rb +1 -3
  26. data/renderers/html.rb +1 -3
  27. data/renderers/rb.rb +11 -9
  28. data/spec/fixtures/assets/application.js.coffee +2 -0
  29. data/spec/lib/flatrack/asset_extensions_spec.rb +13 -0
  30. data/spec/lib/flatrack/cli_spec.rb +58 -0
  31. data/spec/lib/flatrack/renderer/base_spec.rb +4 -0
  32. data/spec/lib/flatrack/renderer_spec.rb +4 -0
  33. data/spec/lib/flatrack/request_spec.rb +22 -0
  34. data/spec/lib/flatrack/response/view_context_spec.rb +76 -0
  35. data/spec/lib/flatrack/response_spec.rb +22 -0
  36. data/spec/lib/flatrack/site_spec.rb +39 -0
  37. data/spec/lib/flatrack_spec.rb +28 -0
  38. data/spec/lib/rake/asset_tasks_spec.rb +55 -0
  39. data/spec/renderers/erb_spec.rb +21 -0
  40. data/spec/renderers/html_spec.rb +21 -0
  41. data/spec/renderers/rb_spec.rb +21 -0
  42. data/spec/spec_helper.rb +14 -2
  43. data/spec/support/site_helper.rb +52 -0
  44. data/templates/.gitignore +2 -1
  45. data/{spec/rake/asset_tasks_spec.rb → templates/.keep} +0 -0
  46. data/templates/404.html +1 -0
  47. data/templates/500.html +1 -0
  48. data/templates/Rakefile +1 -1
  49. data/templates/boot.rb +3 -1
  50. data/templates/javascript.js.coffee +2 -0
  51. data/templates/layout.html.erb +5 -3
  52. data/templates/stylesheet.css.scss +2 -0
  53. metadata +163 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42119bb7fea0d768b2429a668f6813ab2f5e3fcc
4
- data.tar.gz: 80d026fa6cc9481b2cbc11016736e64326c5581d
3
+ metadata.gz: 02f38974206178dab428bdc7d4b7a0c2aa92dc03
4
+ data.tar.gz: b6b70a1a6ea5ddd2a9a4c344c547228715d499c3
5
5
  SHA512:
6
- metadata.gz: 69993fde0808453468c56ea5d8e65b017529c4afacda324d07a31eea32f9359f79d798edd08d3de3d22710c3ab81e56b433e70b5ac780415d7117cfe0ec30ff4
7
- data.tar.gz: c3a3bc2fd839f04279ab32c3b318c8b8830ce2b054cf922f4f60dca97e13292eefd4f4fca5ea5f77d5caffd552a24c3eefd66e9546c7afe3d9511794597368b9
6
+ metadata.gz: 4a2cd97cdcdcd578d7a3af3278ef743c7fbd838eb1d195e7233e406c4cf9a74d0a26c932852fc4c04cf402cdb2a3f55af753911487325de9cfdf6d11c6e32888
7
+ data.tar.gz: 22a927232f2f038a3297ef20e78dd5a605950a032ec411b5cb8796720c461a7faefd9be9c152518f25f345c58c1c2c52d12c2ddda12bcbe9363213ff82f5d3f7
data/.gitignore CHANGED
@@ -1,2 +1,5 @@
1
1
  Gemfile.lock
2
- pkg/*
2
+ pkg/*
3
+ *.gem
4
+ tmp
5
+ coverage
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Excludes:
3
+ - vendor/bundle/**
4
+
5
+ Documentation:
6
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.1.1
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.1
5
+ cache: bundler
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in flatrack-rack.gemspec
4
- gemspec
2
+ gemspec unless ENV['RM_INFO']
@@ -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
- # Flat::Rack
1
+ ![Flatrack](https://raw.github.com/jwaldrip/flatrack/master/logo.png)
2
+ --
2
3
 
3
- TODO: Write a gem description
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
- Add this line to your application's Gemfile:
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
- gem 'flat-rack'
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
- And then execute:
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
- $ bundle
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
- Or install it yourself as:
44
+ $ flatrack start
45
+
46
+ ## How it works
16
47
 
17
- $ gem install flat-rack
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
- ## Usage
50
+ **for example**
20
51
 
21
- TODO: Write usage instructions here
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
@@ -1 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => [:spec]
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'flatrack'
4
- Flatrack::CLI.start
4
+ Flatrack::CLI.start
@@ -6,34 +6,44 @@ require 'flatrack/version'
6
6
  Gem::Specification.new do |spec|
7
7
 
8
8
  # Information
9
- spec.name = "flatrack"
10
- spec.version = Flatrack::VERSION
11
- spec.authors = ["Jason Waldrip"]
12
- spec.email = ["jason@waldrip.net"]
13
- spec.summary = 'A template based flat rack site'
14
- spec.homepage = "https://github.com/jwaldrip/flatrack"
15
- spec.license = "MIT"
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 = `git ls-files`.split($/)
19
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
- spec.require_paths = ["lib"]
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.add_dependency 'rack'
28
- spec.add_dependency 'activesupport'
29
- spec.add_dependency 'sass'
30
- spec.add_dependency 'sprockets'
31
- spec.add_dependency 'sprockets-sass'
32
- spec.add_dependency 'thor'
33
- spec.add_dependency 'coffee-script'
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
@@ -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
- module Flatrack
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
- def self.root
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.register_format(ext, mime)
27
- FORMATS[ext.to_s] = mime
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 self.assets
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
- I18n.enforce_available_locales = false
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
- Dir.glob(File.expand_path File.join __FILE__, '../../renderers/**/*.rb').each { |f| require f }
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
@@ -1,9 +1,7 @@
1
- module Flatrack
1
+ class Flatrack
2
2
  module AssetExtensions
3
-
4
- def asset_path(path, options={})
3
+ def asset_path(path, options = {})
5
4
  File.join('/assets', path.to_s)
6
5
  end
7
-
8
6
  end
9
7
  end
@@ -1,32 +1,83 @@
1
1
  require 'thor'
2
+ require 'flatrack'
2
3
 
3
- module Flatrack
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
- source_root File.join Flatrack.root, '..', 'templates'
11
-
12
- def new(name)
13
- @name = name.titleize
14
- mkdir_p name
15
- path = File.expand_path name
16
- self.destination_root = path
17
- template '.gitignore', '.gitignore'
18
- template 'boot.rb', 'boot.rb'
19
- template 'Rakefile', 'Rakefile'
20
- template 'Gemfile.erb', 'Gemfile'
21
- template 'config.ru', 'config.ru'
22
- template 'layout.html.erb', 'layouts/layout.html.erb'
23
- template 'page.html.erb', 'pages/index.html.erb'
24
- template 'stylesheet.css.scss', 'assets/stylesheet.css.scss'
25
-
26
- Dir.chdir(path) do
27
- system 'bundle install'
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
@@ -1,20 +1,31 @@
1
- module Flatrack
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 = (Dir[File.join 'pages', "#{file}*"] + Dir[File.join 'layouts', "#{file}*"]).first
10
- raise FileNotFound, "could not find #{file}" unless template
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 { |descendant| descendant.renders?(ext) } ||
14
- raise(RendererNotFound, "could not find a renderer for #{file}")
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
- module Flatrack
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