kelredd-sinatra-helpers 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/bin/sinatra +1 -1
  2. data/lib/sinatra_helpers.rb +22 -1
  3. data/lib/sinatra_helpers/generator/app.rb +2 -0
  4. data/lib/sinatra_helpers/generator/file_templates/Rakefile.erb +19 -2
  5. data/lib/sinatra_helpers/generator/file_templates/app.less.erb +1 -0
  6. data/lib/sinatra_helpers/generator/file_templates/app.rb.erb +6 -24
  7. data/lib/sinatra_helpers/generator/file_templates/app_test.rb.erb +18 -0
  8. data/lib/sinatra_helpers/generator/file_templates/boot.rb.erb +17 -0
  9. data/lib/sinatra_helpers/generator/file_templates/console.erb +10 -0
  10. data/lib/sinatra_helpers/generator/file_templates/{deploy_live.rb.erb → deploy_production.rb.erb} +0 -0
  11. data/lib/sinatra_helpers/generator/file_templates/environment.rb.erb +23 -0
  12. data/lib/sinatra_helpers/generator/file_templates/{index.html.erb → environment_development.rb.erb} +0 -0
  13. data/lib/sinatra_helpers/generator/file_templates/environment_production.rb.erb +11 -0
  14. data/lib/sinatra_helpers/generator/file_templates/environment_test.rb.erb +0 -0
  15. data/lib/sinatra_helpers/generator/file_templates/gems.rb.erb +7 -8
  16. data/lib/sinatra_helpers/generator/file_templates/index.html.erb.erb +1 -0
  17. data/lib/sinatra_helpers/generator/file_templates/layout +2 -2
  18. data/lib/sinatra_helpers/generator/file_templates/model_test.rb.erb +13 -0
  19. data/lib/sinatra_helpers/generator/file_templates/production.ru.erb +3 -21
  20. data/lib/sinatra_helpers/generator/file_templates/reset.less.erb +82 -0
  21. data/lib/sinatra_helpers/generator/file_templates/server.erb +9 -0
  22. data/lib/sinatra_helpers/generator/file_templates/test_helper.rb.erb +23 -0
  23. data/lib/sinatra_helpers/generator/template.rb +32 -25
  24. data/lib/sinatra_helpers/less.rb +113 -0
  25. data/lib/sinatra_helpers/sprockets.rb +109 -0
  26. data/lib/sinatra_helpers/version.rb +1 -1
  27. metadata +18 -10
  28. data/lib/sinatra_helpers/generator/file_templates/app_controller.rb.erb +0 -5
  29. data/lib/sinatra_helpers/generator/file_templates/app_helpers.rb.erb +0 -11
  30. data/lib/sinatra_helpers/generator/file_templates/app_initializer.rb.erb +0 -16
  31. data/lib/sinatra_helpers/generator/file_templates/initializers.rb.erb +0 -6
  32. data/lib/sinatra_helpers/generator/file_templates/sprockets.yml.erb +0 -7
  33. data/lib/sinatra_helpers/generator/file_templates/web.css.erb +0 -82
data/bin/sinatra CHANGED
@@ -7,5 +7,5 @@ if ARGV[0]
7
7
  app = SinatraHelpers::Generator::App.new(app_path)
8
8
  app.generate
9
9
  else
10
- puts "Please specify a name for your gem"
10
+ puts "Please specify a name for your sinatra app"
11
11
  end
@@ -1,3 +1,24 @@
1
1
  require 'sinatra_helpers/environment_tests'
2
2
  require 'sinatra_helpers/erb'
3
- require 'sinatra_helpers/generator'
3
+
4
+ module SinatraHelpers
5
+
6
+ HTTP_STATUS = {
7
+ :not_found => 404,
8
+ :ok => 200
9
+ }
10
+
11
+ class << self
12
+
13
+ def page_cache?(app)
14
+ if defined?(Rails)
15
+ Rails.configuration.action_controller.perform_caching
16
+ elsif app.respond_to?(:environment)
17
+ app.environment == 'production'
18
+ else
19
+ false
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -1,4 +1,5 @@
1
1
  require 'erb'
2
+ require 'useful/ruby_extensions/string'
2
3
 
3
4
  module SinatraHelpers; end
4
5
 
@@ -11,6 +12,7 @@ module SinatraHelpers::Generator
11
12
  def initialize(path)
12
13
  @root_path = File.dirname(path)
13
14
  self.name = File.basename(path)
15
+ @class_name = @name.classify
14
16
  end
15
17
 
16
18
  def name=(name)
@@ -1,4 +1,21 @@
1
1
  require 'rubygems'
2
-
3
- require 'config/gems.rb'
4
2
  require 'gemsconfig/tasks/rake'
3
+ require 'rake/testtask'
4
+
5
+ namespace :test do
6
+
7
+ Rake::TestTask.new(:units) do |t|
8
+ t.libs << "test"
9
+ t.pattern = 'test/unit/**/*_test.rb'
10
+ t.verbose = true
11
+ end
12
+ Rake::Task['test:units'].comment = "Run the unit tests"
13
+
14
+ Rake::TestTask.new(:app) do |t|
15
+ t.libs << "test"
16
+ t.pattern = 'test/functional/**/*_test.rb'
17
+ t.verbose = true
18
+ end
19
+ Rake::Task['test:app'].comment = "Run the functional tests"
20
+
21
+ end
@@ -0,0 +1 @@
1
+ /* TODO: put any application less code here */
@@ -1,27 +1,9 @@
1
- %w(yaml erb rubygems sinatra config/gems).each do |lib|
2
- require lib
3
- end
4
-
5
- Gemsconfig::load if defined?(Gemsconfig)
6
- require 'config/initializers'
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'config/boot'
7
4
 
8
- # TODO: set your session cookie name here
9
- use Rack::Session::Cookie, :key => '_sess'
10
- use Rack::Flash
11
-
12
- # Load in helpers
13
- Dir[File.join(File.dirname(__FILE__), "app/helpers" ,"*.rb")].each do |file|
14
- require "app/helpers/#{File.basename(file, ".rb")}"
15
- end
5
+ # define routes here or load in route definitions
16
6
 
17
- # Load in models
18
- Dir[File.join(File.dirname(__FILE__), "app/models" ,"*.rb")].each do |file|
19
- require "app/models/#{File.basename(file, ".rb")}"
7
+ get '/' do
8
+ erb :'index.html'
20
9
  end
21
-
22
- # Load in controllers
23
- Dir[File.join(File.dirname(__FILE__), "app/controllers" ,"*.rb")].each do |file|
24
- load File.join(File.dirname(__FILE__), 'app/controllers', File.basename(file))
25
- end
26
-
27
- set :views, File.join(File.dirname(__FILE__), 'app', 'views')
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class AppTest < Test::Unit::TestCase
4
+
5
+ def app
6
+ Sinatra::Application
7
+ end
8
+
9
+ context "The app" do
10
+
11
+ should "say hello" do
12
+ visit '/'
13
+ assert_contain "Hello from <%= @class_name %>!"
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,17 @@
1
+ RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
2
+ ROOT_DIR = File.expand_path("#{File.dirname(__FILE__)}/..") unless defined? ROOT_DIR
3
+
4
+ def root_path(*args)
5
+ File.join(ROOT_DIR, *args)
6
+ end
7
+
8
+ def public_path(*args)
9
+ root_path('public', *args)
10
+ end
11
+
12
+ begin
13
+ require "config/environments/#{RACK_ENV.downcase}"
14
+ rescue LoadError => err
15
+ puts "no environment config set up for '#{RACK_ENV.downcase}', ignoring..."
16
+ end
17
+ require 'config/environment'
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ platform_irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ require 'rubygems'
6
+ require 'sinatra/base'
7
+ libs = " -r app"
8
+
9
+ puts "Loading default environment (Sinatra #{Sinatra::VERSION})"
10
+ exec "#{platform_irb} #{libs} --simple-prompt"
@@ -0,0 +1,23 @@
1
+ require 'config/gems'
2
+ Gemsconfig::load if defined?(Gemsconfig)
3
+
4
+ # basic app configurations
5
+ set :root, root_path
6
+ set :views, root_path("app", "views")
7
+ set :images_path, public_path("images")
8
+ set :environment, RACK_ENV.to_sym if defined?(RACK_ENV)
9
+
10
+ # TODO: set your session cookie name here
11
+ use Rack::Session::Cookie, :key => '_sess'
12
+ use Rack::Flash
13
+
14
+ # setup the LESS helper
15
+ SinatraHelpers::Less.config do |config|
16
+ # => TODO: add less stylesheets to cache here
17
+ config.stylesheets = ['reset', 'app']
18
+ config.cache_name = 'web'
19
+ end
20
+ Sinatra::Application.register SinatraHelpers::Less
21
+
22
+ # setup the Sprockets helper
23
+ Sinatra::Application.register SinatraHelpers::Sprockets
@@ -0,0 +1,11 @@
1
+ require 'rack/cache'
2
+ use Rack::Cache,
3
+ :verbose => true,
4
+ :metastore => "file:#{root_path('cache-rack', 'meta')}",
5
+ :entitystore => "file:#{root_path('cache-rack', 'body')}"
6
+
7
+
8
+ FileUtils.mkdir_p 'log' unless File.exists?('log')
9
+ log = File.new("log/#{RACK_ENV.downcase}.log", "a+")
10
+ $stdout.reopen(log)
11
+ $stderr.reopen(log)
@@ -1,19 +1,18 @@
1
1
  begin
2
2
  require 'gemsconfig'
3
3
  rescue LoadError => err
4
- p " ** can't load gemsconfig. gem install kelredd-gemsconfig --source http://gems.github.com **"
4
+ puts " ** can't load gemsconfig. gem install kelredd-gemsconfig **"
5
5
  end
6
6
 
7
7
  Gemsconfig::init do |config|
8
8
 
9
- config.gem 'kelredd-useful', :lib => 'useful/ruby_extensions', :source => 'http://gemcutter.org'
10
-
11
- config.gem 'rack-flash', :lib => 'rack-flash', :source => 'http://gemcutter.org'
12
- config.gem 'rack-cache', :lib => false, :source => 'http://gemcutter.org'
9
+ config.gem 'rack-flash', :lib => 'rack-flash'
10
+ config.gem 'rack-cache', :lib => false
13
11
 
14
- config.gem 'kelredd-sinatra-helpers', :lib => 'sinatra_helpers', :source => 'http://gemcutter.org'
12
+ config.gem 'kelredd-useful', :lib => 'useful/ruby_extensions'
15
13
 
16
- config.gem 'sprockets'
17
- config.gem 'kelredd-sprockets-sinatra', :lib => 'sprockets_sinatra', :source => 'http://gems.github.com'
14
+ config.gem 'kelredd-sinatra-helpers', :lib => 'sinatra_helpers'
15
+ config.gem 'kelredd-sinatra-helpers', :lib => 'sinatra_helpers/less'
16
+ config.gem 'kelredd-sinatra-helpers', :lib => 'sinatra_helpers/sprockets'
18
17
 
19
18
  end if defined?(Gemsconfig)
@@ -0,0 +1 @@
1
+ <h1>Hello from <%= @class_name %>!</h1>
@@ -11,9 +11,9 @@
11
11
  <meta name="robots" content="noindex,nofollow" />
12
12
  <% end %>
13
13
  <link rel="icon" type="image/png" href="/favicon.png"></link>
14
- <%= stylesheet_link_tag :web, :media => "all" %>
14
+ <%= stylesheet_link_tag SinatraHelpers::Less[:stylesheets], :cache => SinatraHelpers::Less[:cache_name], :media => "all" %>
15
15
  <% unless @noscript %>
16
- <%= sprockets_include_tag %>
16
+ <%= javascript_include_tag 'app.js' %>
17
17
  <% end %>
18
18
  </head>
19
19
  <body class="body">
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class UnitTest < Test::Unit::TestCase
4
+
5
+ context "An example unit test" do
6
+
7
+ should "flunk" do
8
+ flunk "This is just an example from a template. Please provide some tests"
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -1,24 +1,6 @@
1
- FileUtils.mkdir_p 'log' unless File.exists?('log')
2
- log = File.new("log/production.log", "a+")
3
- $stdout.reopen(log)
4
- $stderr.reopen(log)
5
-
6
- require 'rubygems'
7
- require 'sinatra'
1
+ RACK_ENV = ENV["RACK_ENV"] ||= "production" unless defined? RACK_ENV
8
2
  require 'app'
9
-
10
- root_dir = File.dirname(__FILE__)
11
-
12
- set :root, root_dir
13
- set :app_file, File.join(root_dir, 'app.rb')
14
- set :environment, :production
3
+ set :app_file, File.join(root_path, 'app.rb')
15
4
  disable :run
16
5
 
17
- require 'rack/cache'
18
-
19
- use Rack::Cache,
20
- :verbose => true,
21
- :metastore => "file:#{File.join(root_dir, 'cache-rack', 'meta')}",
22
- :entitystore => "file:#{File.join(root_dir, 'cache-rack', 'body')}"
23
-
24
- run Sinatra::Application
6
+ run Sinatra::Application
@@ -0,0 +1,82 @@
1
+ /*
2
+ Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3
+ Code licensed under the BSD License:
4
+ http://developer.yahoo.net/yui/license.txt
5
+ version: 2.7.0
6
+ */
7
+ html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var,optgroup{font-style:inherit;font-weight:inherit;}del,ins{text-decoration:none;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:baseline;}sub{vertical-align:baseline;}legend{color:#000;}input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;}input,button,textarea,select{*font-size:100%;}body{font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}select,input,button,textarea,button{font:99% arial,helvetica,clean,sans-serif;}table{font-size:inherit;font:100%;}pre,code,kbd,samp,tt{font-family:monospace;*font-size:108%;line-height:100%;}
8
+
9
+ /*
10
+ Copyright (c) 2009, Kelly Redding. All rights reserved.
11
+ See http://github.com/kelredd/sinatra-helpers for license details
12
+ */
13
+ UL {
14
+ margin: 0;
15
+ padding: 0;
16
+ }
17
+ UL LI {
18
+ list-style-image: none;
19
+ list-style-position: outside;
20
+ list-style-type: none;
21
+ }
22
+ UL.bulleted LI {
23
+ list-style-position: inside !important;
24
+ list-style-type: disc !important;
25
+ }
26
+
27
+ OL LI {
28
+ list-style-type: decimal;
29
+ }
30
+
31
+ HTML {
32
+ font-size:10pt;
33
+ }
34
+ BODY {
35
+ width: 100%;
36
+ font-family: "Lucida Grande", Verdana, sans-serif;
37
+ font-size: 1em;
38
+ font-size-adjust: none;
39
+ font-variant: normal;
40
+ }
41
+ A, IMG, FORM, FIELDSET {
42
+ border: 0px none;
43
+ padding: 0;
44
+ margin: 0;
45
+ }
46
+ INPUT, SELECT, TEXTAREA, BUTTON {
47
+ margin: 0;
48
+ padding: .2em .3em;
49
+ font-family : 'Lucida Grande', sans-serif;
50
+ font-size: 9px;
51
+ font-size-adjust: none;
52
+ font-variant: normal;
53
+ }
54
+ INPUT[type="submit"],
55
+ INPUT[type="checkbox"], DIV.checkbox LABEL,
56
+ INPUT[type="radiobutton"] {
57
+ cursor: pointer;
58
+ vertical-align: middle;
59
+ }
60
+ INPUT[type="checkbox"] {
61
+ margin-right: .2em;
62
+ }
63
+ SELECT {
64
+ padding: 0;
65
+ }
66
+
67
+ /* IE fixes */
68
+ HTML, BODY {
69
+ height:100%;
70
+ }
71
+
72
+ /* Add the style below to a container element that contains floats - will cause the container
73
+ to expand to the height of the floats */
74
+ .clearfix:after {
75
+ content: ".";
76
+ display: block;
77
+ height: 0;
78
+ clear: both;
79
+ visibility: hidden;
80
+ }
81
+ /* Hides from IE-mac \*/
82
+ * html .clearfix {height: 1%;}
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ platform_ruby = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'ruby.bat' : 'ruby'
4
+
5
+ require 'rubygems'
6
+ require 'sinatra/base'
7
+
8
+ puts "Loading default environment (Sinatra #{Sinatra::VERSION})"
9
+ exec "#{platform_ruby} app.rb"
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda/test_unit'
4
+ require 'context'
5
+ require 'useful/shoulda_macros/test_unit'
6
+ require 'rack/test'
7
+ require 'webrat'
8
+
9
+ RACK_ENV = "test"
10
+ require 'app'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+
14
+ class Test::Unit::TestCase
15
+ include Rack::Test::Methods
16
+ include Webrat::Methods
17
+ include Webrat::Matchers
18
+
19
+ Webrat.configure do |config|
20
+ config.mode = :rack
21
+ end
22
+
23
+ end
@@ -9,56 +9,63 @@ module SinatraHelpers::Generator
9
9
  'gitignore.erb' => '.gitignore',
10
10
 
11
11
  :admin => {
12
- 'production.ru.erb' => 'production.ru'
12
+ 'production.ru.erb' => 'production.ru',
13
+ :vhosts => {},
14
+ :logrotate => {}
13
15
  },
14
16
 
15
17
  :app => {
16
- :controllers => {
17
- 'app_controller.rb.erb' => 'app.rb'
18
- },
19
- :helpers => {
20
- 'app_helpers.rb.erb' => 'app_helpers.rb'
21
- },
22
18
  :javascripts => {
23
19
  'app.js.erb' => 'app.js'
24
20
  },
25
21
  :models => {},
26
- :stylesheets => {},
22
+ :stylesheets => {
23
+ 'reset.less.erb' => 'reset.less',
24
+ 'app.less.erb' => 'app.less'
25
+ },
27
26
  :views => {
28
27
  'layout' => 'layout.erb',
29
- :app => {
30
- 'index.html.erb' => 'index.html.erb'
31
- }
32
- }
28
+ 'index.html.erb.erb' => 'index.html.erb'
29
+ },
33
30
  },
34
31
 
35
32
  :config => {
33
+ 'boot.rb.erb' => 'boot.rb',
34
+ 'deploy.rb.erb' => 'deploy.rb',
36
35
  :deploy => {
37
- 'deploy_live.rb.erb' => 'live.rb',
36
+ 'deploy_production.rb.erb' => 'production.rb',
38
37
  'deploy_staging.rb.erb' => 'staging.rb'
39
38
  },
40
- 'deploy.rb.erb' => 'deploy.rb',
41
- 'gems.rb.erb' => 'gems.rb',
42
- :initializers => {
43
- 'app_initializer.rb.erb' => 'app.rb'
39
+ 'environment.rb.erb' => 'environment.rb',
40
+ :environments => {
41
+ 'environment_development.rb.erb' => 'development.rb',
42
+ 'environment_test.rb.erb' => 'test.rb',
43
+ 'environment_production.rb.erb' => 'production.rb'
44
44
  },
45
- 'initializers.rb.erb' => 'initializers.rb',
46
- 'sprockets.yml.erb' => 'sprockets.yml'
45
+ 'gems.rb.erb' => 'gems.rb'
47
46
  },
48
47
 
49
48
  :log => {},
50
49
 
51
50
  :public => {
52
51
  :images => {},
53
- :javascripts => {},
54
- :stylesheets => {
55
- 'web.css.erb' => 'web.css'
56
- }
57
52
  },
58
53
 
59
- :vendor => {
60
- :javascripts => {}
54
+ :script => {
55
+ 'console.erb' => 'console',
56
+ 'server.erb' => 'server'
57
+ },
58
+
59
+ :test => {
60
+ 'test_helper.rb.erb' => 'test_helper.rb',
61
+ :functional => {
62
+ 'app_test.rb.erb' => 'app_test.rb'
63
+ },
64
+ :unit => {
65
+ 'model_test.rb.erb' => 'model_test.rb'
66
+ }
61
67
  }
68
+
62
69
  }
63
70
 
64
71
  end
@@ -0,0 +1,113 @@
1
+ begin
2
+ require 'less'
3
+ rescue LoadError => err
4
+ err.message << "\n**** Install less (gem install less) to use the sinatra less helpers ****\n"
5
+ raise err
6
+ end
7
+
8
+ module SinatraHelpers; end
9
+ module SinatraHelpers::Less
10
+
11
+ CONTENT_TYPE = "text/css"
12
+ DEFAULT_CACHE_CONTROL = 'public, max-age=86400' # cache for 24 hours
13
+
14
+ class Config
15
+ ATTRIBUTES = [:hosted_root, :src_root, :stylesheets, :cache_name, :cache_control, :compression]
16
+ DEFAULTS = {
17
+ :hosted_root => '/stylesheets',
18
+ :src_root => 'app/stylesheets',
19
+ :cache_name => 'all',
20
+ :stylesheets => [],
21
+ :cache_control => DEFAULT_CACHE_CONTROL,
22
+ :compression => false
23
+ }
24
+
25
+ attr_accessor *ATTRIBUTES
26
+
27
+ def initialize(args={})
28
+ ATTRIBUTES.each do |a|
29
+ instance_variable_set("@#{a}", args[a] || DEFAULTS[a])
30
+ end
31
+ end
32
+ end
33
+
34
+ class << self
35
+ attr_reader :app
36
+
37
+ def config
38
+ if instance_variable_get("@config").nil?
39
+ instance_variable_set("@config", SinatraHelpers::Less::Config.new)
40
+ end
41
+ yield instance_variable_get("@config") if block_given?
42
+ instance_variable_get("@config")
43
+ end
44
+
45
+ def [](config_attribute)
46
+ config.send(config_attribute)
47
+ end
48
+
49
+ def registered(app)
50
+ instance_variable_set("@app", app)
51
+
52
+ app.get "/less-sinatra-helper-test" do
53
+ if SinatraHelpers::Less.config
54
+ "The LESS sinatra helper is configured and ready :)"
55
+ else
56
+ "The LESS sinatra helper is NOT configured and ready :("
57
+ end
58
+ end
59
+
60
+ app.get "#{SinatraHelpers::Less[:hosted_root]}/*.css" do
61
+ css_name = params['splat'].first.to_s
62
+ less_path = File.join([
63
+ app.root, SinatraHelpers::Less[:src_root], "#{css_name}.less"
64
+ ])
65
+ css_path = File.join([
66
+ app.root, SinatraHelpers::Less[:src_root], "#{css_name}.css"
67
+ ])
68
+
69
+ content_type CONTENT_TYPE
70
+ if SinatraHelpers.page_cache?(SinatraHelpers::Less.app)
71
+ headers['Cache-Control'] = SinatraHelpers::Less[:cache_control]
72
+ end
73
+
74
+ if File.exists?(less_path)
75
+ SinatraHelpers::Less.compile(css_name, [less_path])
76
+ elsif File.exists?(css_path)
77
+ SinatraHelpers::Less.compile(css_name, [css_path])
78
+ elsif SinatraHelpers::Less[:cache_name] && css_name == SinatraHelpers::Less[:cache_name]
79
+ less_paths = SinatraHelpers::Less[:stylesheets].collect do |css_name|
80
+ File.join(app.root, SinatraHelpers::Less[:src_root], "#{css_name}.less")
81
+ end.select do |less_path|
82
+ File.exists?(less_path)
83
+ end
84
+ SinatraHelpers::Less.compile(css_name, less_paths)
85
+ else
86
+ halt SinatraHelpers::HTTP_STATUS[:not_found]
87
+ end
88
+ end
89
+ end
90
+
91
+ def compile(css_name, file_paths)
92
+ compiled_less = file_paths.collect do |file_path|
93
+ Less::Engine.new(File.new(file_path)).to_css
94
+ end.join("\n")
95
+ compiled_less.delete!("\n") if use_compression?
96
+ if SinatraHelpers.page_cache?(SinatraHelpers::Less.app)
97
+ pub_path = File.join(SinatraHelpers::Less.app.public, SinatraHelpers::Less[:hosted_root])
98
+ FileUtils.mkdir_p(pub_path)
99
+ hosted = File.join(pub_path, "#{css_name}.css")
100
+ File.open(hosted, "w") do |file|
101
+ file.write(compiled_less)
102
+ end
103
+ end
104
+ compiled_less
105
+ end
106
+
107
+ def use_compression?
108
+ SinatraHelpers::Less[:compression]
109
+ end
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,109 @@
1
+ begin
2
+ require 'sprockets'
3
+ rescue LoadError => err
4
+ err.message << "\n**** Install sprockets (gem install sprockets) to use the sinatra sprockets helpers ****\n"
5
+ raise err
6
+ end
7
+
8
+ module SinatraHelpers; end
9
+ module SinatraHelpers::Sprockets
10
+
11
+ CONTENT_TYPE = "text/javascript; charset=utf-8"
12
+ DEFAULT_CACHE_CONTROL = 'public, max-age=86400' # cache for 24 hours
13
+
14
+ class Config
15
+ ATTRIBUTES = [:hosted_root, :src_root, :load_path, :expand_paths, :cache_control]
16
+ DEFAULTS = {
17
+ :hosted_root => '/javascripts',
18
+ :src_root => 'app/javascripts',
19
+ :load_path => ['app/javascripts/**', 'vendor/javascripts', 'vendor/sprockets'],
20
+ :expand_paths => true,
21
+ :cache_control => DEFAULT_CACHE_CONTROL
22
+ }
23
+
24
+ attr_accessor *ATTRIBUTES
25
+
26
+ def initialize(args={})
27
+ ATTRIBUTES.each do |a|
28
+ instance_variable_set("@#{a}", args[a] || DEFAULTS[a])
29
+ end
30
+ end
31
+ end
32
+
33
+ class << self
34
+ attr_reader :app
35
+
36
+ def config
37
+ if instance_variable_get("@config").nil?
38
+ instance_variable_set("@config", SinatraHelpers::Sprockets::Config.new)
39
+ end
40
+ yield instance_variable_get("@config") if block_given?
41
+ instance_variable_get("@config")
42
+ end
43
+
44
+ def secretary
45
+ if instance_variable_get("@secretary").nil?
46
+ instance_variable_set("@secretary", {
47
+ :root => app.root,
48
+ :load_path => config.load_path,
49
+ :expand_paths => config.expand_paths
50
+ })
51
+ end
52
+ yield instance_variable_get("@secretary") if block_given?
53
+ instance_variable_get("@secretary")
54
+ end
55
+
56
+ def [](config_attribute)
57
+ config.send(config_attribute)
58
+ end
59
+
60
+ def registered(app)
61
+ instance_variable_set("@app", app)
62
+
63
+ app.get "/sprockets-sinatra-helper-test" do
64
+ if SinatraHelpers::Sprockets.config
65
+ "The sprockets sinatra helper is configured and ready :)"
66
+ else
67
+ "The sprockets sinatra helper is NOT configured and ready :("
68
+ end
69
+ end
70
+
71
+ app.get "#{SinatraHelpers::Sprockets[:hosted_root]}/*.js" do
72
+ src_name = params['splat'].first.to_s
73
+ src_file_path = File.join([
74
+ SinatraHelpers::Sprockets[:src_root], "#{src_name}.js"
75
+ ])
76
+ src_path = File.join(app.root, src_file_path)
77
+
78
+ content_type CONTENT_TYPE
79
+ if SinatraHelpers.page_cache?(SinatraHelpers::Sprockets.app)
80
+ headers['Cache-Control'] = SinatraHelpers::Sprockets[:cache_control]
81
+ end
82
+
83
+ if File.exists?(src_path)
84
+ SinatraHelpers::Sprockets.compile(src_file_path)
85
+ else
86
+ halt SinatraHelpers::HTTP_STATUS[:not_found]
87
+ end
88
+ end
89
+ end
90
+
91
+ def compile(src_file_name)
92
+ secretary_params = SinatraHelpers::Sprockets.secretary do |params|
93
+ params[:source_files] = [src_file_name]
94
+ end
95
+ compiled_src = Sprockets::Secretary.new(secretary_params).concatenation.to_s
96
+ if SinatraHelpers.page_cache?(SinatraHelpers::Sprockets.app)
97
+ pub_path = File.join(SinatraHelpers::Sprockets.app.public, SinatraHelpers::Sprockets[:hosted_root])
98
+ FileUtils.mkdir_p(pub_path)
99
+ hosted = File.join(pub_path, File.basename(src_file_name))
100
+ File.open(hosted, "w") do |file|
101
+ file.write(compiled_src)
102
+ end
103
+ end
104
+ compiled_src
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -3,7 +3,7 @@ module SinatraHelpers
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 3
6
+ TINY = 4
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-sinatra-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-22 00:00:00 -06:00
12
+ date: 2009-12-23 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,25 +39,33 @@ files:
39
39
  - lib/sinatra_helpers/erb.rb
40
40
  - lib/sinatra_helpers/generator/app.rb
41
41
  - lib/sinatra_helpers/generator/file_templates/app.js.erb
42
+ - lib/sinatra_helpers/generator/file_templates/app.less.erb
42
43
  - lib/sinatra_helpers/generator/file_templates/app.rb.erb
43
- - lib/sinatra_helpers/generator/file_templates/app_controller.rb.erb
44
- - lib/sinatra_helpers/generator/file_templates/app_helpers.rb.erb
45
- - lib/sinatra_helpers/generator/file_templates/app_initializer.rb.erb
44
+ - lib/sinatra_helpers/generator/file_templates/app_test.rb.erb
45
+ - lib/sinatra_helpers/generator/file_templates/boot.rb.erb
46
46
  - lib/sinatra_helpers/generator/file_templates/Capfile.erb
47
+ - lib/sinatra_helpers/generator/file_templates/console.erb
47
48
  - lib/sinatra_helpers/generator/file_templates/deploy.rb.erb
48
- - lib/sinatra_helpers/generator/file_templates/deploy_live.rb.erb
49
+ - lib/sinatra_helpers/generator/file_templates/deploy_production.rb.erb
49
50
  - lib/sinatra_helpers/generator/file_templates/deploy_staging.rb.erb
51
+ - lib/sinatra_helpers/generator/file_templates/environment.rb.erb
52
+ - lib/sinatra_helpers/generator/file_templates/environment_development.rb.erb
53
+ - lib/sinatra_helpers/generator/file_templates/environment_production.rb.erb
54
+ - lib/sinatra_helpers/generator/file_templates/environment_test.rb.erb
50
55
  - lib/sinatra_helpers/generator/file_templates/gems.rb.erb
51
56
  - lib/sinatra_helpers/generator/file_templates/gitignore.erb
52
- - lib/sinatra_helpers/generator/file_templates/index.html.erb
53
- - lib/sinatra_helpers/generator/file_templates/initializers.rb.erb
57
+ - lib/sinatra_helpers/generator/file_templates/index.html.erb.erb
54
58
  - lib/sinatra_helpers/generator/file_templates/layout
59
+ - lib/sinatra_helpers/generator/file_templates/model_test.rb.erb
55
60
  - lib/sinatra_helpers/generator/file_templates/production.ru.erb
56
61
  - lib/sinatra_helpers/generator/file_templates/Rakefile.erb
57
- - lib/sinatra_helpers/generator/file_templates/sprockets.yml.erb
58
- - lib/sinatra_helpers/generator/file_templates/web.css.erb
62
+ - lib/sinatra_helpers/generator/file_templates/reset.less.erb
63
+ - lib/sinatra_helpers/generator/file_templates/server.erb
64
+ - lib/sinatra_helpers/generator/file_templates/test_helper.rb.erb
59
65
  - lib/sinatra_helpers/generator/template.rb
60
66
  - lib/sinatra_helpers/generator.rb
67
+ - lib/sinatra_helpers/less.rb
68
+ - lib/sinatra_helpers/sprockets.rb
61
69
  - lib/sinatra_helpers/version.rb
62
70
  - lib/sinatra_helpers.rb
63
71
  has_rdoc: true
@@ -1,5 +0,0 @@
1
- get %r{/($|index($|.html|.htm))} do
2
- headers['Cache-Control'] = 'public, max-age=7200' if production? # rack::cache for 2 hours
3
- erb 'app/index.html'.to_sym
4
- end
5
-
@@ -1,11 +0,0 @@
1
- require 'sinatra/base'
2
-
3
- module Sinatra
4
- module AppHelpers
5
-
6
- # TODO: put any application helpers here
7
-
8
- end
9
-
10
- helpers AppHelpers
11
- end
@@ -1,16 +0,0 @@
1
- module Config; end
2
- module Config::Initializers; end
3
-
4
- module Config::Initializers::App
5
- def self.registered(app)
6
-
7
- app.configure do
8
-
9
- # TODO: put some initializer code in here
10
-
11
- end
12
-
13
- end
14
- end
15
-
16
- Sinatra::Application.register Config::Initializers::App
@@ -1,6 +0,0 @@
1
- module Config; end
2
- module Config::Initializers; end
3
-
4
- Dir["config/initializers/*.rb"].each do |file|
5
- require "config/initializers/#{File.basename(file, ".rb")}"
6
- end
@@ -1,7 +0,0 @@
1
- :file_name: app
2
- :asset_root: public
3
- :load_path:
4
- - app/javascripts
5
- - vendor/javascripts/*/src
6
- :source_files:
7
- - app/app.js
@@ -1,82 +0,0 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
- /* some base styles */
15
- UL {
16
- margin: 0;
17
- padding: 0;
18
- list-style-image: none;
19
- list-style-position: inside;
20
- list-style-type:none;
21
- }
22
- UL.bulleted {
23
- list-style-type: disc !important;
24
- }
25
- OL {
26
- display: block;
27
- list-style-type: decimal;
28
- margin: 1em 0;
29
- }
30
-
31
- HTML {
32
- font-size:10pt;
33
- }
34
- BODY {
35
- width: 100%;
36
- font-family: "Lucida Grande", Verdana, sans-serif;
37
- font-size: 1em;
38
- font-size-adjust:none;
39
- font-variant: normal;
40
- }
41
- A, IMG, FORM, FIELDSET {
42
- border: 0px none;
43
- padding: 0;
44
- margin: 0;
45
- }
46
- INPUT, SELECT, TEXTAREA, BUTTON {
47
- margin: 0;
48
- padding: .2em .3em;
49
- font-family : 'Lucida Grande', sans-serif;
50
- font-size: 9px;
51
- font-size-adjust: none;
52
- font-variant: normal;
53
- }
54
- INPUT[type="submit"],
55
- INPUT[type="checkbox"], DIV.checkbox LABEL,
56
- INPUT[type="radiobutton"] {
57
- cursor: pointer;
58
- vertical-align: middle;
59
- }
60
- INPUT[type="checkbox"] {
61
- margin-right: .2em;
62
- }
63
- SELECT {
64
- padding: 0;
65
- }
66
-
67
- /* IE fixes */
68
- HTML, BODY {
69
- height:100%;
70
- }
71
-
72
- /* Add the style below to a container element that contains floats - will cause the container
73
- to expand to the height of the floats */
74
- .clearfix:after {
75
- content: ".";
76
- display: block;
77
- height: 0;
78
- clear: both;
79
- visibility: hidden;
80
- }
81
- /* Hides from IE-mac \*/
82
- * html .clearfix {height: 1%;}