flatrack 0.0.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d90823dca4b0df1edc0c568691ac712057a7ea2
4
- data.tar.gz: 99bdd53e90658a39b0e169be58ac515a6dadb61f
3
+ metadata.gz: f26f0173c80797ab99000a3ace4dd3420d755a06
4
+ data.tar.gz: 284e097be8f77ad7dcdda15e532d01a3f127085d
5
5
  SHA512:
6
- metadata.gz: 81a880337d5fdc94f45b21cf9184e2ec7bb1ed986265aafbca65dcf8a2e23891c3046fc80bfe2b3ea555c7b8fb708aed2fa693ce59e84388f1f90e013bb3fd31
7
- data.tar.gz: 9e4fc3e262e518ce79f3954e5ce807653db9d23f8ff37879635ab5f6d2c317a72723ad1c1b73141b1aab30f655aa68c7618f017878ac908987769ddf52dab489
6
+ metadata.gz: aaecd5dfd29f80cc54b8a6d5d4f3444b91a4d43cc62e46a01d640d0cb5e00e03669486ef60f640ebd9e6f5a2f3ee70f5adfdd4cf34ebe93b7a2fd9126ddbfe5b
7
+ data.tar.gz: a4c0c83aa72a5bd0f91fa9d26e309f24b97a228358c71ae5c4fb5b9416cedf6492f969d96bf467ea8408c663ac95a02caed4d2a6fc6a81b74966630772b655ee
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ pkg/*
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Excludes:
3
+ - vendor/bundle/**
4
+
5
+ Documentation:
6
+ Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in flatrack-rack.gemspec
4
+ <<<<<<< Updated upstream
4
5
  gemspec
6
+ =======
7
+ gemspec unless ENV['RM_INFO']
8
+ >>>>>>> Stashed changes
data/bin/flatrack CHANGED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'flatrack'
4
+ Flatrack::CLI.start
data/flatrack.gemspec CHANGED
@@ -6,28 +6,29 @@ 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 = 'A template based flat rack site'
14
+ spec.homepage = "https://github.com/jwaldrip/flatrack"
15
+ spec.license = "MIT"
16
16
 
17
17
  # 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"]
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"]
22
22
 
23
23
  # Ruby Version
24
- spec.required_ruby_version = '>= 1.6.8'
24
+ spec.required_ruby_version = '>= 1.9.3'
25
25
 
26
26
  # Dependencies
27
27
  spec.add_dependency 'rack'
28
28
  spec.add_dependency 'activesupport'
29
29
  spec.add_dependency 'sass'
30
30
  spec.add_dependency 'sprockets'
31
+ spec.add_dependency 'sprockets-sass'
31
32
  spec.add_dependency 'thor'
32
33
  spec.add_dependency 'coffee-script'
33
34
  spec.add_dependency 'rake'
@@ -1,9 +1,7 @@
1
1
  module Flatrack
2
2
  module AssetExtensions
3
-
4
3
  def asset_path(path, options={})
5
- File.join('assets', path.to_s)
4
+ File.join('/assets', path.to_s)
6
5
  end
7
-
8
6
  end
9
7
  end
@@ -0,0 +1,50 @@
1
+ require 'thor'
2
+ require 'flatrack'
3
+
4
+ module Flatrack
5
+ class CLI < Thor
6
+ include FileUtils
7
+ include Thor::Actions
8
+
9
+ source_root File.join Flatrack.gem_root, '..', 'templates'
10
+
11
+ desc 'new NAME', 'create a new flatrack site with the given name'
12
+
13
+ def new(name)
14
+ @name = name.titleize
15
+ mkdir_p name
16
+ path = File.expand_path name
17
+ self.destination_root = path
18
+
19
+ # Store keep files
20
+ template '.keep', 'assets/stylesheets/.keep'
21
+ template '.keep', 'assets/javascripts/.keep'
22
+ template '.keep', 'assets/images/.keep'
23
+ template '.keep', 'pages/.keep'
24
+ template '.keep', 'layouts/.keep'
25
+
26
+ # Write from templates
27
+ template '.gitignore', '.gitignore'
28
+ template 'boot.rb', 'boot.rb'
29
+ template 'Rakefile', 'Rakefile'
30
+ template 'Gemfile.erb', 'Gemfile'
31
+ template 'config.ru', 'config.ru'
32
+ template 'layout.html.erb', 'layouts/layout.html.erb'
33
+ template 'page.html.erb', 'pages/index.html.erb'
34
+ template 'stylesheet.css.scss', 'assets/stylesheets/main.css.scss'
35
+ template 'javascript.js.coffee', 'assets/javascripts/main.js.coffee'
36
+
37
+ Dir.chdir(path) do
38
+ system 'bundle install'
39
+ end
40
+ end
41
+
42
+ desc 'start PORT', 'run the site on the given port'
43
+
44
+ def start(port=5959)
45
+ require './boot'
46
+ Rack::Server.start app: Flatrack::Site, Port: port
47
+ end
48
+
49
+ end
50
+ end
@@ -10,7 +10,7 @@ module Flatrack
10
10
  raise FileNotFound, "could not find #{file}" unless template
11
11
  ext = File.extname(template).sub(/\./, '')
12
12
 
13
- renderer = Base.descendants.find { |descendant| descendant.renders?(ext) } ||
13
+ renderer = Base.descendants.find { |descendant| descendant.renders?(ext) } ||
14
14
  raise(RendererNotFound, "could not find a renderer for #{file}")
15
15
 
16
16
  renderer.new template
@@ -7,7 +7,7 @@ module Flatrack
7
7
 
8
8
  def initialize(env)
9
9
  @rack_request = Rack::Request.new(env)
10
- @env = env
10
+ @env = env
11
11
  end
12
12
 
13
13
  def path
@@ -1,13 +1,14 @@
1
1
  module Flatrack
2
2
  class Response
3
3
  class ViewContext
4
+ include AssetExtensions
4
5
 
5
6
  def initialize(response)
6
7
  @response = response
7
8
  end
8
9
 
9
- def get_binding
10
- binding
10
+ def get_binding(&block)
11
+ binding(&block)
11
12
  end
12
13
 
13
14
  def path
@@ -31,7 +32,7 @@ module Flatrack
31
32
 
32
33
  def javascript_tag(uri)
33
34
  uri = File.join('/assets', uri.to_s) + '.js' if uri.is_a? Symbol
34
- html_tag(:script, src: uri){ nil }
35
+ html_tag(:script, src: uri) { nil }
35
36
  end
36
37
 
37
38
  def stylesheet_tag(uri)
@@ -40,19 +41,19 @@ module Flatrack
40
41
  end
41
42
 
42
43
  def page_stylesheet_tag
43
- file = @response.send(:file_for, path.to_s)
44
- base_path = File.join File.dirname(file), File.basename(file, '.*')
44
+ file = @response.send(:file_for, path.to_s)
45
+ base_path = File.join File.dirname(file), File.basename(file, '.*')
45
46
  stylesheet_tag base_path if stylesheet_exists?(base_path)
46
47
  end
47
48
 
48
49
  def link_to(name, link, options={})
49
50
  link = [link, options.delete(:params).to_param].join('?') if options[:params].is_a?(Hash) && options[:params].present?
50
- html_tag(:a, { href: link }.merge(options) ){ name }
51
+ html_tag(:a, { href: link }.merge(options)) { name }
51
52
  end
52
53
 
53
54
  def html_tag(tag, options={}, &block)
54
55
  [].tap do |lines|
55
- lines << "<#{tag} " + options.map{ |k, v| "#{k}=\"#{v}\"" }.join(' ') + (block_given? ? ">" : "/>")
56
+ lines << "<#{tag} " + options.map { |k, v| "#{k}=\"#{v}\"" }.join(' ') + (block_given? ? ">" : "/>")
56
57
  if block_given?
57
58
  lines << yield
58
59
  lines << "</#{tag}>"
@@ -3,7 +3,7 @@ module Flatrack
3
3
 
4
4
  autoload :ViewContext, 'flatrack/response/view_context'
5
5
 
6
- DEFAULT_FILE = 'index'
6
+ DEFAULT_FILE = 'index'
7
7
  CONTENT_TYPES = {
8
8
  html: 'text/html',
9
9
  rb: 'text/html'
@@ -42,10 +42,10 @@ module Flatrack
42
42
 
43
43
  def render_file(file = nil, options={})
44
44
  status, layout = options.values_at(:status, :layout)
45
- layout ||= :layout
46
- file ||= file_for(request.path)
47
- contents = renderer_for(file).render(view_context)
48
- contents = layout_for(layout).render(view_context){ contents } if layout
45
+ layout ||= :layout
46
+ file ||= file_for(request.path)
47
+ contents = renderer_for(file).render(view_context)
48
+ contents = layout_for(layout).render(view_context) { contents } if layout
49
49
  self.body << contents
50
50
  [status, headers, body]
51
51
  end
data/lib/flatrack/site.rb CHANGED
@@ -1,12 +1,21 @@
1
+ require 'rack/server'
2
+
1
3
  module Flatrack
2
4
  Site = Rack::Builder.app do
5
+
6
+ # Static Assets Should be served directly
7
+ use Rack::Static, urls: ["/favicon.ico", "assets"], root: "public"
8
+
9
+ Flatrack.middleware.each do |middleware|
10
+ use *middleware
11
+ end
12
+
3
13
  map '/assets' do
4
14
  run Flatrack.assets
5
15
  end
6
16
 
7
17
  map '/' do
8
- use Rack::Static, urls: ["/favicon.ico", "assets"], root: "public"
9
- run ->(env){ Request.new(env).response }
18
+ run ->(env) { Request.new(env).response }
10
19
  end
11
20
  end
12
21
  end
@@ -1,3 +1,3 @@
1
1
  module Flatrack
2
- VERSION = "0.0.1"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/flatrack.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'flatrack/version'
2
- require 'sprockets'
3
2
  require 'active_support/all'
3
+ require 'sprockets'
4
+ require 'sprockets-sass'
5
+ require 'sass'
6
+ require 'rack'
4
7
 
5
8
  module Flatrack
6
9
  extend ActiveSupport::Autoload
@@ -10,14 +13,26 @@ module Flatrack
10
13
  autoload :Response
11
14
  autoload :Site
12
15
  autoload :AssetExtensions
16
+ autoload :CLI
13
17
 
14
18
  RendererNotFound = Class.new StandardError
15
19
  FileNotFound = Class.new StandardError
16
20
 
17
- FORMATS = {
18
- 'html' => 'text/html',
19
- 'rb' => 'text/html'
20
- }
21
+ FORMATS = {}
22
+
23
+ def self.gem_root
24
+ File.expand_path File.join __FILE__, '..'
25
+ end
26
+
27
+ def self.site_root
28
+ File.expand_path Dir.pwd
29
+ end
30
+
31
+ def self.config(&block)
32
+ yield self
33
+ end
34
+
35
+ protected
21
36
 
22
37
  def self.assets
23
38
  @assets ||= begin
@@ -30,8 +45,25 @@ module Flatrack
30
45
  end
31
46
  end
32
47
 
48
+ def self.register_format(ext, mime)
49
+ FORMATS[ext.to_s] = mime
50
+ end
51
+
52
+ def self.middleware
53
+ @middleware ||= []
54
+ end
55
+
56
+ def self.use(*args)
57
+ self.middleware << args
58
+ end
59
+
60
+ # By default we know how to render 'text/html'
61
+ register_format :html, 'text/html'
62
+
63
+ # Fix Locales issue
33
64
  I18n.enforce_available_locales = false
34
65
 
66
+ # Load all renderers
35
67
  Dir.glob(File.expand_path File.join __FILE__, '../../renderers/**/*.rb').each { |f| require f }
36
68
 
37
69
  end
@@ -56,36 +56,16 @@ module Rake
56
56
  def assets
57
57
  Dir['assets/**/*.*'].map do |file|
58
58
  file_basename = File.basename file
59
- file = file.split('.').tap(&:pop).join('.') if file_basename.split('.').size > 2
60
- File.expand_path(file).sub(/(#{environment.paths.join('|')})\//,'')
59
+ parts = file_basename.split('.').size
60
+ file = file.split('.').tap(&:pop).join('.') if parts > 2
61
+ File.expand_path(file).sub(/(#{environment.paths.join('|')})\//, '')
61
62
  end
62
63
  end
63
64
 
64
65
  # Define tasks
65
66
  def define
66
- namespace :assets do
67
- desc 'precompile assets'
68
- task :precompile do
69
- with_logger do
70
- manifest.compile(assets)
71
- end
72
- end
73
-
74
- desc "Remove all assets"
75
- task :clobber do
76
- with_logger do
77
- manifest.clobber
78
- end
79
- end
80
-
81
- desc "Clean old assets"
82
- task :clean do
83
- with_logger do
84
- manifest.clean(keep)
85
- end
86
- end
87
-
88
- end
67
+ file = File.expand_path File.join __FILE__, '../assets.rake'
68
+ eval File.read file
89
69
  end
90
70
 
91
71
  private
@@ -0,0 +1,22 @@
1
+ namespace :assets do
2
+ desc 'precompile assets'
3
+ task :precompile do
4
+ with_logger do
5
+ manifest.compile(assets)
6
+ end
7
+ end
8
+
9
+ desc "Remove all assets"
10
+ task :clobber do
11
+ with_logger do
12
+ manifest.clobber
13
+ end
14
+ end
15
+
16
+ desc "Clean old assets"
17
+ task :clean do
18
+ with_logger do
19
+ manifest.clean(keep)
20
+ end
21
+ end
22
+ end
data/logo.png ADDED
Binary file
data/renderers/erb.rb CHANGED
@@ -5,7 +5,7 @@ class Flatrack::Renderer::ERB < Flatrack::Renderer::Base
5
5
  renders :erb
6
6
 
7
7
  def render(context = binding, &block)
8
- ::ERB.new(contents).result(context, &block)
8
+ ::ERB.new(contents).result context.get_binding(&block)
9
9
  end
10
10
 
11
11
  end
data/renderers/rb.rb CHANGED
@@ -5,9 +5,9 @@ class Flatrack::Renderer::Rb < Flatrack::Renderer::Base
5
5
  renders :rb
6
6
 
7
7
  def render(context)
8
- result = nil
8
+ result = nil
9
9
  evaluator = Thread.start do
10
- $SAFE = 3
10
+ $SAFE = 3
11
11
  result = eval contents, context
12
12
  end
13
13
  nil while evaluator.alive?
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,6 @@ require 'flatrack'
4
4
 
5
5
  RSpec.configure do |config|
6
6
  config.treat_symbols_as_metadata_keys_with_true_values = true
7
- config.run_all_when_everything_filtered = true
7
+ config.run_all_when_everything_filtered = true
8
8
  config.filter_run :focus
9
9
  end
@@ -0,0 +1,3 @@
1
+ public/assets
2
+ .sass-cache
3
+ tmp
data/templates/.keep ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'flatrack', '~> <%= Flatrack::VERSION %>'
@@ -0,0 +1,4 @@
1
+ require './boot'
2
+ require 'rake/asset_tasks'
3
+
4
+ Rake::AssetTasks.new
data/templates/boot.rb ADDED
@@ -0,0 +1,4 @@
1
+ STDOUT.sync = true
2
+
3
+ require 'bundler/setup'
4
+ Bundler.require(:default)
@@ -0,0 +1,2 @@
1
+ require './boot'
2
+ run Flatrack::Site
File without changes
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <title>
4
+ <% @name %></title>
5
+ <%%= stylesheet_tag :main %>
6
+ <%%= javascript_tag :main %>
7
+ </head>
8
+ <body>
9
+ <%%= yield %>
10
+ </body>
@@ -0,0 +1 @@
1
+ Welcome to <%= @name %>, this is your first page! You can find me at pages/index.html.erb
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flatrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Waldrip
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sprockets-sass
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: thor
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -144,9 +158,10 @@ executables:
144
158
  extensions: []
145
159
  extra_rdoc_files: []
146
160
  files:
161
+ - ".gitignore"
147
162
  - ".rspec"
163
+ - ".rubocop.yml"
148
164
  - Gemfile
149
- - Gemfile.lock
150
165
  - LICENSE.txt
151
166
  - README.md
152
167
  - Rakefile
@@ -154,6 +169,7 @@ files:
154
169
  - flatrack.gemspec
155
170
  - lib/flatrack.rb
156
171
  - lib/flatrack/asset_extensions.rb
172
+ - lib/flatrack/cli.rb
157
173
  - lib/flatrack/renderer.rb
158
174
  - lib/flatrack/renderer/base.rb
159
175
  - lib/flatrack/request.rb
@@ -162,12 +178,24 @@ files:
162
178
  - lib/flatrack/site.rb
163
179
  - lib/flatrack/version.rb
164
180
  - lib/rake/asset_tasks.rb
181
+ - lib/rake/assets.rake
182
+ - logo.png
165
183
  - renderers/erb.rb
166
184
  - renderers/html.rb
167
185
  - renderers/rb.rb
168
186
  - spec/lib/flatrack_spec.rb
169
187
  - spec/rake/asset_tasks_spec.rb
170
188
  - spec/spec_helper.rb
189
+ - templates/.gitignore
190
+ - templates/.keep
191
+ - templates/Gemfile.erb
192
+ - templates/Rakefile
193
+ - templates/boot.rb
194
+ - templates/config.ru
195
+ - templates/javascript.js.coffee
196
+ - templates/layout.html.erb
197
+ - templates/page.html.erb
198
+ - templates/stylesheet.css.scss
171
199
  homepage: https://github.com/jwaldrip/flatrack
172
200
  licenses:
173
201
  - MIT
@@ -180,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
208
  requirements:
181
209
  - - ">="
182
210
  - !ruby/object:Gem::Version
183
- version: 1.6.8
211
+ version: 1.9.3
184
212
  required_rubygems_version: !ruby/object:Gem::Requirement
185
213
  requirements:
186
214
  - - ">="
@@ -188,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
216
  version: '0'
189
217
  requirements: []
190
218
  rubyforge_project:
191
- rubygems_version: 2.2.0
219
+ rubygems_version: 2.2.2
192
220
  signing_key:
193
221
  specification_version: 4
194
222
  summary: A template based flat rack site
data/Gemfile.lock DELETED
@@ -1,61 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- flatrack (0.0.1)
5
- activesupport
6
- coffee-script
7
- rack
8
- rake
9
- sass
10
- sprockets
11
- thor
12
-
13
- GEM
14
- remote: https://rubygems.org/
15
- specs:
16
- activesupport (4.0.2)
17
- i18n (~> 0.6, >= 0.6.4)
18
- minitest (~> 4.2)
19
- multi_json (~> 1.3)
20
- thread_safe (~> 0.1)
21
- tzinfo (~> 0.3.37)
22
- atomic (1.1.14)
23
- coffee-script (2.2.0)
24
- coffee-script-source
25
- execjs
26
- coffee-script-source (1.6.3)
27
- diff-lcs (1.2.5)
28
- execjs (2.0.2)
29
- hike (1.2.3)
30
- i18n (0.6.9)
31
- minitest (4.7.5)
32
- multi_json (1.8.2)
33
- rack (1.5.2)
34
- rake (10.1.0)
35
- rspec (2.14.1)
36
- rspec-core (~> 2.14.0)
37
- rspec-expectations (~> 2.14.0)
38
- rspec-mocks (~> 2.14.0)
39
- rspec-core (2.14.7)
40
- rspec-expectations (2.14.4)
41
- diff-lcs (>= 1.1.3, < 2.0)
42
- rspec-mocks (2.14.4)
43
- sass (3.2.12)
44
- sprockets (2.10.1)
45
- hike (~> 1.2)
46
- multi_json (~> 1.0)
47
- rack (~> 1.0)
48
- tilt (~> 1.1, != 1.3.0)
49
- thor (0.18.1)
50
- thread_safe (0.1.3)
51
- atomic
52
- tilt (1.4.1)
53
- tzinfo (0.3.38)
54
-
55
- PLATFORMS
56
- ruby
57
-
58
- DEPENDENCIES
59
- bundler (~> 1.5)
60
- flatrack!
61
- rspec