kelredd-sinatra-helpers 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ module SinatraHelpers
7
7
  :not_found => 404,
8
8
  :ok => 200
9
9
  }
10
+ DEFAULT_CACHE_CONTROL = 'public, max-age=86400' # cache for 24 hours
10
11
 
11
12
  class << self
12
13
 
@@ -12,12 +12,11 @@ use Rack::Session::Cookie, :key => '_sess'
12
12
  use Rack::Flash
13
13
 
14
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
15
  Sinatra::Application.register SinatraHelpers::Less
16
+ require 'sinatra_helpers/less/erb'
17
+ Sinatra::Application.helpers SinatraHelpers::Less::Erb
21
18
 
22
19
  # setup the Sprockets helper
23
20
  Sinatra::Application.register SinatraHelpers::Sprockets
21
+ require 'sinatra_helpers/sprockets/erb'
22
+ Sinatra::Application.helpers SinatraHelpers::Sprockets::Erb
@@ -9,3 +9,7 @@ FileUtils.mkdir_p 'log' unless File.exists?('log')
9
9
  log = File.new("log/#{RACK_ENV.downcase}.log", "a+")
10
10
  $stdout.reopen(log)
11
11
  $stderr.reopen(log)
12
+
13
+ SinatraHelpers::Less.configure do |config|
14
+ config.compress = true
15
+ end
@@ -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 SinatraHelpers::Less[:stylesheets], :cache => SinatraHelpers::Less[:cache_name], :media => "all" %>
14
+ <%= less_link_tag 'reset', 'app', :media => "all", :concat => 'web' %>
15
15
  <% unless @noscript %>
16
- <%= javascript_include_tag 'app.js' %>
16
+ <%= sprockets_include_tag 'app.js' %>
17
17
  <% end %>
18
18
  </head>
19
19
  <body class="body">
@@ -36,11 +36,11 @@ module SinatraHelpers::Generator
36
36
  'deploy_production.rb.erb' => 'production.rb',
37
37
  'deploy_staging.rb.erb' => 'staging.rb'
38
38
  },
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'
39
+ 'env.rb.erb' => 'env.rb',
40
+ :envs => {
41
+ 'env_development.rb.erb' => 'development.rb',
42
+ 'env_test.rb.erb' => 'test.rb',
43
+ 'env_production.rb.erb' => 'production.rb'
44
44
  },
45
45
  'gems.rb.erb' => 'gems.rb'
46
46
  },
@@ -5,32 +5,13 @@ rescue LoadError => err
5
5
  raise err
6
6
  end
7
7
 
8
+ require 'sinatra_helpers/less/config'
9
+
8
10
  module SinatraHelpers; end
9
11
  module SinatraHelpers::Less
10
12
 
11
13
  CONTENT_TYPE = "text/css"
12
- DEFAULT_CACHE_CONTROL = 'public, max-age=86400' # cache for 24 hours
13
14
 
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
15
  class << self
35
16
  attr_reader :app
36
17
 
@@ -75,8 +56,8 @@ module SinatraHelpers::Less
75
56
  SinatraHelpers::Less.compile(css_name, [less_path])
76
57
  elsif File.exists?(css_path)
77
58
  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|
59
+ elsif SinatraHelpers::Less[:concat].include?(css_name)
60
+ less_paths = SinatraHelpers::Less[:concat][css_name].collect do |css_name|
80
61
  File.join(app.root, SinatraHelpers::Less[:src_root], "#{css_name}.less")
81
62
  end.select do |less_path|
82
63
  File.exists?(less_path)
@@ -105,7 +86,7 @@ module SinatraHelpers::Less
105
86
  end
106
87
 
107
88
  def use_compression?
108
- SinatraHelpers::Less[:compression]
89
+ SinatraHelpers::Less[:compress]
109
90
  end
110
91
 
111
92
  end
@@ -0,0 +1,23 @@
1
+ module SinatraHelpers; end
2
+ module SinatraHelpers::Less
3
+
4
+ class Config
5
+ ATTRIBUTES = [:hosted_root, :src_root, :concat, :cache_control, :compress]
6
+ DEFAULTS = {
7
+ :hosted_root => '/stylesheets',
8
+ :src_root => 'app/stylesheets',
9
+ :concat => {},
10
+ :cache_control => SinatraHelpers::DEFAULT_CACHE_CONTROL,
11
+ :compress => false
12
+ }
13
+
14
+ attr_accessor *ATTRIBUTES
15
+
16
+ def initialize(args={})
17
+ ATTRIBUTES.each do |a|
18
+ instance_variable_set("@#{a}", args[a] || DEFAULTS[a])
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,32 @@
1
+ require "sinatra_helpers/erb"
2
+ require 'useful/ruby_extensions/object' unless ::Object.new.respond_to?('blank?')
3
+
4
+ module SinatraHelpers; end
5
+ module SinatraHelpers::Less
6
+
7
+ module Erb
8
+
9
+ def less_link_tag(*args)
10
+ the_args = args.flatten
11
+ srcs, options = if the_args.last && the_args.last.kind_of?(::Hash)
12
+ [the_args[0..-2], the_args.last]
13
+ else
14
+ [the_args, {}]
15
+ end
16
+
17
+ options[:environment] ||= SinatraHelpers::Less.app.environment.to_s
18
+
19
+ concat = options.delete(:concat)
20
+ if concat && !(concat.to_s).blank?
21
+ SinatraHelpers::Less.config do |config|
22
+ config.concat[concat.to_s] = srcs
23
+ end
24
+ srcs = concat.to_s if SinatraHelpers.page_cache?(SinatraHelpers::Less.app)
25
+ end
26
+
27
+ stylesheet_link_tag srcs, options
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -5,30 +5,12 @@ rescue LoadError => err
5
5
  raise err
6
6
  end
7
7
 
8
+ require 'sinatra_helpers/sprockets/config'
9
+
8
10
  module SinatraHelpers; end
9
11
  module SinatraHelpers::Sprockets
10
12
 
11
13
  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
14
 
33
15
  class << self
34
16
  attr_reader :app
@@ -0,0 +1,23 @@
1
+ module SinatraHelpers; end
2
+ module SinatraHelpers::Sprockets
3
+
4
+ class Config
5
+ ATTRIBUTES = [:hosted_root, :src_root, :load_path, :expand_paths, :cache_control]
6
+ DEFAULTS = {
7
+ :hosted_root => '/javascripts',
8
+ :src_root => 'app/javascripts',
9
+ :load_path => ['app/javascripts/**', 'vendor/javascripts', 'vendor/sprockets'],
10
+ :expand_paths => true,
11
+ :cache_control => SinatraHelpers::DEFAULT_CACHE_CONTROL
12
+ }
13
+
14
+ attr_accessor *ATTRIBUTES
15
+
16
+ def initialize(args={})
17
+ ATTRIBUTES.each do |a|
18
+ instance_variable_set("@#{a}", args[a] || DEFAULTS[a])
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,24 @@
1
+ require "sinatra_helpers/erb"
2
+ require 'useful/ruby_extensions/object' unless ::Object.new.respond_to?('blank?')
3
+
4
+ module SinatraHelpers; end
5
+ module SinatraHelpers::Sprockets
6
+
7
+ module Erb
8
+
9
+ def sprockets_include_tag(*args)
10
+ the_args = args.flatten
11
+ srcs, options = if the_args.last && the_args.last.kind_of?(::Hash)
12
+ [the_args[0..-2], the_args.last]
13
+ else
14
+ [the_args, {}]
15
+ end
16
+
17
+ options[:environment] ||= SinatraHelpers::Less.app.environment.to_s
18
+
19
+ javascript_include_tag srcs, options
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -3,7 +3,7 @@ module SinatraHelpers
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 4
6
+ TINY = 5
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.4
4
+ version: 0.1.5
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-12-23 00:00:00 -06:00
12
+ date: 2009-12-24 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -48,10 +48,10 @@ files:
48
48
  - lib/sinatra_helpers/generator/file_templates/deploy.rb.erb
49
49
  - lib/sinatra_helpers/generator/file_templates/deploy_production.rb.erb
50
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
51
+ - lib/sinatra_helpers/generator/file_templates/env.rb.erb
52
+ - lib/sinatra_helpers/generator/file_templates/env_development.rb.erb
53
+ - lib/sinatra_helpers/generator/file_templates/env_production.rb.erb
54
+ - lib/sinatra_helpers/generator/file_templates/env_test.rb.erb
55
55
  - lib/sinatra_helpers/generator/file_templates/gems.rb.erb
56
56
  - lib/sinatra_helpers/generator/file_templates/gitignore.erb
57
57
  - lib/sinatra_helpers/generator/file_templates/index.html.erb.erb
@@ -64,7 +64,11 @@ files:
64
64
  - lib/sinatra_helpers/generator/file_templates/test_helper.rb.erb
65
65
  - lib/sinatra_helpers/generator/template.rb
66
66
  - lib/sinatra_helpers/generator.rb
67
+ - lib/sinatra_helpers/less/config.rb
68
+ - lib/sinatra_helpers/less/erb.rb
67
69
  - lib/sinatra_helpers/less.rb
70
+ - lib/sinatra_helpers/sprockets/config.rb
71
+ - lib/sinatra_helpers/sprockets/erb.rb
68
72
  - lib/sinatra_helpers/sprockets.rb
69
73
  - lib/sinatra_helpers/version.rb
70
74
  - lib/sinatra_helpers.rb