padrino-contrib 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of padrino-contrib might be problematic. Click here for more details.

data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in padrino-contrib.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Padrino
1
+ Copyright (c) 2011 Padrino
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -21,8 +21,8 @@ In your Padrino project edit:
21
21
 
22
22
  # boot.rb
23
23
  require 'padrino-contrib/exception_notifier'
24
- # require 'padrino-contrib/orm/ar/permalink'
25
- # require 'padrino-contrib/orm/ar/textile'
24
+ # require 'padrino-contrib/orm/active_record/permalink'
25
+ # require 'padrino-contrib/orm/active_record/textile'
26
26
 
27
27
  Padrino.load! # Remember to add contribs before that line!
28
28
 
data/Rakefile CHANGED
@@ -1,62 +1,27 @@
1
- require 'rubygems/specification' unless defined?(Gem::Specification)
2
- require 'rake' unless defined?(Rake)
1
+ require 'rubygems' unless defined?(Gem)
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
3
4
 
4
- # Runs the sh command with sudo if the rake command is run with sudo
5
- def sudo_sh(command)
6
- command = `whoami`.strip! != "root" ? "sudo #{command}" : command
7
- sh command
8
- end
9
-
10
- # Returns the gem specification object for a gem
11
- def gemspec
12
- @gemspec ||= begin
13
- ::Gem::Specification.load("padrino-contrib.gemspec")
5
+ %w(install release).each do |task|
6
+ Rake::Task[task].enhance do
7
+ sh "rm -rf pkg"
14
8
  end
15
9
  end
16
10
 
17
- # Most notable functions are:
18
- # $ rake package # packages the gem into the pkg folder
19
- # $ rake install # installs the gem into system
20
- # $ rake release # publishes gem to rubygems
21
-
22
- desc "Validates the gemspec"
23
- task :gemspec do
24
- gemspec.validate
25
- end
26
-
27
- desc "Displays the current version"
28
- task :version do
29
- puts "Current version: #{gemspec.version}"
11
+ desc "Bump version on github"
12
+ task :bump do
13
+ puts "\e[31mNothing to commit (working directory clean)\e[0m" and return unless `git status -s`.chomp!
14
+ version = Bundler.load_gemspec(Dir[File.expand_path('../*.gemspec', __FILE__)].first).version
15
+ sh "git add .; git commit -a -m \"Bump to version #{version}\""
30
16
  end
31
17
 
32
- desc "Installs the gem locally"
33
- task :install => :package do
34
- sudo_sh "gem install pkg/#{gemspec.name}-#{gemspec.version}"
35
- end
18
+ task :release => :bump
36
19
 
37
- desc "Uninstalls the gem locally"
38
- task :uninstall do
39
- sudo_sh "gem uninstall padrino-contrib -v #{gemspec.version}"
40
- end
41
-
42
- desc "Release the gem"
43
- task :release => :package do
44
- sh "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
45
- sh "rm -rf pkg"
46
- sh "git add . && git commit -m 'Bump to version #{gemspec.version}' && git push"
47
- end
48
-
49
- # rake package
50
- begin
51
- require 'rake/gempackagetask'
52
- rescue LoadError
53
- task(:gem) { $stderr.puts '`gem install rake` to package gems' }
54
- else
55
- Rake::GemPackageTask.new(gemspec) do |pkg|
56
- pkg.gem_spec = gemspec
57
- end
58
- task :gem => :gemspec
20
+ desc "Run complete application spec suite"
21
+ RSpec::Core::RakeTask.new("spec") do |t|
22
+ t.skip_bundler = true
23
+ t.pattern = './spec/**/*_spec.rb'
24
+ t.rspec_opts = %w(-fs --color --fail-fast)
59
25
  end
60
26
 
61
- task :package => :gemspec
62
- task :default => :install
27
+ task :default => :spec
@@ -0,0 +1,12 @@
1
+ module Padrino
2
+ module Contrib
3
+ autoload :VERSION, 'padrino-contrib/version.rb'
4
+ autoload :AutoLocale, 'padrino-contrib/auto_locale.rb'
5
+ autoload :ExceptionNotifier, 'padrino-contrib/exception_notifier.rb'
6
+ autoload :FlashSession, 'padrino-contrib/flash_session'
7
+
8
+ module Helpers
9
+ autoload :AssetsCompressor, 'padrino-contrib/helpers/assets_compressor.rb'
10
+ end # Helpers
11
+ end # Contrib
12
+ end # Padrino
@@ -14,6 +14,11 @@ module Padrino
14
14
  # use Padrino::Contrib::FlashSession, settings.session_id
15
15
  #
16
16
  class FlashSession
17
+
18
+ def self.registered(app)
19
+ app.use Padrino::Contrib::FlashSession, app.session_id
20
+ end
21
+
17
22
  def initialize(app, session_key = 'session_id')
18
23
  @app = app
19
24
  @session_key = session_key.to_s
@@ -9,25 +9,31 @@ module Padrino
9
9
  # ==== Usage
10
10
  #
11
11
  # # in your app.rb
12
- # use Padrino::Contrib::Helpers::AssetsCompressor
12
+ # register Padrino::Contrib::Helpers::AssetsCompressor
13
13
  #
14
14
  # # in yours layouts/views
15
- # =stylesheet_link_tag "grid", "base", "fancybox", "gallery", :cache => "bundle/lipsiasample"
16
- # =javascript_include_tag "jquery", "gallery", "fancybox", "base", :cache => "bundle/lipsiasample"
15
+ # =stylesheet_link_tag "grid", "base", "fancybox", "gallery", :cache => "bundle/sample"
16
+ # =javascript_include_tag "jquery", "gallery", "fancybox", "base", :cache => "bundle/sample"
17
17
  # =stylesheet_link_tag "grid", "base", "fancybox", "gallery", :cache => true
18
18
  # =javascript_include_tag "jquery", "gallery", "fancybox", "base", :cache => true
19
19
  #
20
20
  module AssetsCompressor
21
- def self.registered(app)
21
+ def self.registered(app, options={})
22
22
  raise "You need to add in your Gemfile: gem 'yui-compressor', :require => 'yui/compressor'" unless defined?(YUI)
23
23
  app.helpers Padrino::Contrib::Helpers::AssetsCompressor::Helpers unless app.respond_to?(:compressor)
24
24
  app.set :compressor, {}
25
+
26
+ # Setup YUI Compressor
27
+ options.reverse_merge!(:line_break => 8000)
28
+ app.compressor[:css] = YUI::CssCompressor.new(options)
29
+ app.compressor[:js] = YUI::JavaScriptCompressor.new(options)
25
30
  end
26
31
 
27
32
  module Helpers
28
33
  def self.included(base)
29
34
  base.alias_method_chain :javascript_include_tag, :compression
30
35
  base.alias_method_chain :stylesheet_link_tag, :compression
36
+ base.alias_method_chain :asset_path, :compression
31
37
  end
32
38
 
33
39
  def javascript_include_tag_with_compression(*sources)
@@ -38,22 +44,61 @@ module Padrino
38
44
  stylesheet_link_tag_without_compression(*assets_compressor(:css, sources))
39
45
  end
40
46
 
47
+ def cache_asset(file, options={}, &block)
48
+ began_at = Time.now
49
+ kind = File.extname(file).sub(/\./, '').to_sym
50
+ original = Dir[File.join(settings.views, file).sub(/#{kind}$/, "*")][0]
51
+ mtime = File.mtime(original).to_i
52
+ file = file.sub(/#{kind}$/, "#{mtime}.#{kind}")
53
+ path = Padrino.root("public", uri_root_path(file))
54
+
55
+ if !File.exist?(path)
56
+ source = block.call
57
+
58
+ if options[:compress]
59
+ source = settings.compressor[kind].compress(source)
60
+ end
61
+
62
+ Dir.mkdir(File.dirname(path)) unless File.exist?(File.dirname(path))
63
+ File.open(path, "w") { |f| f.write(source) }
64
+ logger.debug "Compressed (%0.2fms) %s" % [Time.now-began_at, path] if defined?(logger)
65
+ end
66
+
67
+ redirect file
68
+ end
69
+
41
70
  def assets_compressor(kind, sources)
42
71
  options = sources.extract_options!.symbolize_keys
43
72
  bundle = options.delete(:cache)
44
73
  return sources if bundle.nil?
74
+
45
75
  began_at = Time.now
46
76
  asset_folder = case kind
47
77
  when :css then 'stylesheets'
48
78
  when :js then 'javascripts'
49
79
  else raise "YUI Compressor didn't support yet #{kind} compression"
50
80
  end
51
- bundle = settings.app_name if bundle.is_a?(TrueClass)
81
+
82
+ bundle = settings.app_name.downcase if bundle.is_a?(TrueClass)
83
+ path = Padrino.root("public", uri_root_path(asset_folder, bundle.to_s))
84
+
85
+ # Detect changes
86
+ stamps = sources.inject(0) do |memo, source|
87
+ asset_path_without_compression(kind, source) =~ /\?(\d{10})$/
88
+ memo += $1.to_i
89
+ memo
90
+ end
91
+
92
+ bundle = "#{bundle}.#{stamps}" if stamps > 0
52
93
  path = Padrino.root("public", uri_root_path(asset_folder, bundle.to_s))
53
94
  path += ".#{kind}" unless path =~ /\.#{kind}/
95
+
96
+ # Back if no changes happens
54
97
  return bundle if File.exist?(path)
55
- sources.map! do |source|
56
- source = asset_path(kind, source).sub(/\?.*/, '') # Removes Timestamp
98
+
99
+ # Get source code
100
+ code = sources.map do |source|
101
+ source = asset_path(kind, source).sub(/\?\d{10}$/, '') # Removes Timestamp
57
102
  source = source =~ /^http/ ? open(source) : File.read(Padrino.root("public", source))
58
103
  # Removes extra comments
59
104
  if cs = source =~ /\/\*\!/
@@ -62,15 +107,32 @@ module Padrino
62
107
  cr = source.slice(cs, ce+2)
63
108
  source.sub!(cr,'')
64
109
  end
65
- source
110
+ source.each_line.reject { |l| l.strip == "" }.join
66
111
  end
67
- settings.compressor[:css] ||= YUI::CssCompressor.new(:line_break => 8000)
68
- settings.compressor[:js] ||= YUI::JavaScriptCompressor.new(:line_break => 8000)
112
+
113
+ # Write the new bundled file
69
114
  Dir.mkdir(File.dirname(path)) unless File.exist?(File.dirname(path))
70
- File.open(path, "w") { |f| f.write(settings.compressor[kind].compress(sources.join("\n"))) }
115
+ File.open(path, "w") { |f| f.write(settings.compressor[kind].compress(code.join("\n"))) }
71
116
  logger.debug "Compressed (%0.2fms) %s" % [Time.now-began_at, path] if defined?(logger)
117
+
118
+ # Return the updated bundle
72
119
  bundle
73
120
  end
121
+
122
+ def asset_path_with_compression(kind, source)
123
+ file = asset_path_without_compression(kind, source)
124
+ find_last_modified(file)
125
+ end
126
+
127
+ private
128
+ def find_last_modified(file)
129
+ file_was, file = file, file.sub(/\?\d+$/, '')
130
+ return file unless File.exist?(file)
131
+ path = Padrino.root("public", uri_root_path(file))
132
+ path = path.sub(/\.\d{10}\./, '').sub(/#{File.extname(file)}$/, '')
133
+ found = Dir[path+"*"].sort[-1]
134
+ found ? found.sub(/^.*public/, '') : file_was
135
+ end
74
136
  end # Helpers
75
137
  end # AssetsCompressor
76
138
  end # Helpers
@@ -1,7 +1,7 @@
1
1
  module Padrino
2
2
  module Contrib
3
3
  module Orm
4
- module Ar
4
+ module ActiveRecord
5
5
  ##
6
6
  # This module extend ActiveRecord.
7
7
  #
@@ -42,4 +42,4 @@ module Padrino
42
42
  end # Orm
43
43
  end # Contrib
44
44
  end # Padrino
45
- ActiveRecord::Base.extend(Padrino::Contrib::Orm::Ar::Permalink::ClassMethods)
45
+ ::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Permalink::ClassMethods)
@@ -1,7 +1,7 @@
1
1
  module Padrino
2
2
  module Contrib
3
3
  module Orm
4
- module Ar
4
+ module ActiveRecord
5
5
  ##
6
6
  # This module extend ActiveRecord.
7
7
  #
@@ -53,4 +53,4 @@ module Padrino
53
53
  end # Orm
54
54
  end # Contrib
55
55
  end # Padrino
56
- ActiveRecord::Base.extend(Padrino::Contrib::Orm::Ar::PermalinkI18n::ClassMethods)
56
+ ::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::PermalinkI18n::ClassMethods)
@@ -3,7 +3,7 @@ require 'RedCloth'
3
3
  module Padrino
4
4
  module Contrib
5
5
  module Orm
6
- module Ar
6
+ module ActiveRecord
7
7
  ##
8
8
  # This module generate html from textile.
9
9
  #
@@ -50,4 +50,4 @@ module Padrino
50
50
  end # Orm
51
51
  end # Contrib
52
52
  end # Padrino
53
- ActiveRecord::Base.extend(Padrino::Contrib::Orm::Ar::Textile::ClassMethods)
53
+ ::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Textile::ClassMethods)
@@ -1,7 +1,7 @@
1
1
  module Padrino
2
2
  module Contrib
3
3
  module Orm
4
- module Ar
4
+ module ActiveRecord
5
5
  ##
6
6
  # This is an extension for ActiveRecord where if I had:
7
7
  #
@@ -40,4 +40,4 @@ module Padrino
40
40
  end # Orm
41
41
  end # Contrib
42
42
  end # Padrino
43
- ActiveRecord::Base.extend(Padrino::Contrib::Orm::Ar::Translate::ClassMethods)
43
+ ::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Translate::ClassMethods)
@@ -1,7 +1,7 @@
1
1
  module Padrino
2
2
  module Contrib
3
3
  module Orm
4
- module Mm
4
+ module MongoMapper
5
5
  ##
6
6
  # This module extend ActiveRecord.
7
7
  #
@@ -48,4 +48,4 @@ module Padrino
48
48
  end # Orm
49
49
  end # Contrib
50
50
  end # Padrino
51
- MongoMapper::Document.send(:include, Padrino::Contrib::Orm::Mm::Permalink)
51
+ ::MongoMapper::Document.send(:include, Padrino::Contrib::Orm::MongoMapper::Permalink)
@@ -1,7 +1,7 @@
1
1
  module Padrino
2
2
  module Contrib
3
3
  module Orm
4
- module Mm
4
+ module MongoMapper
5
5
  ##
6
6
  # This module provides full text search in specified fileds with pagination support.
7
7
  #
@@ -37,4 +37,4 @@ module Padrino
37
37
  end # Orm
38
38
  end # Contrib
39
39
  end # Padrino
40
- MongoMapper::Document.send(:include, Padrino::Contrib::Orm::Mm::Search)
40
+ ::MongoMapper::Document.send(:include, Padrino::Contrib::Orm::MongoMapper::Search)
@@ -1,17 +1,5 @@
1
- ##
2
- # Manages current Padrino Contrib version for use in gem generation.
3
- #
4
- # We put this in a separate file so you can get padrino version
5
- # without include full padrino contrib.
6
- #
7
1
  module Padrino
8
2
  module Contrib
9
- VERSION = '0.0.6' unless defined?(Padrino::Contrib::VERSION)
10
- ##
11
- # Return the current Padrino version
12
- #
13
- def self.version
14
- VERSION
15
- end
16
- end # Contrib
17
- end # Padrino
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -1,18 +1,20 @@
1
- require File.expand_path("../lib/padrino-contrib/version.rb", __FILE__)
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "padrino-contrib/version"
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = "padrino-contrib"
5
- s.rubyforge_project = "padrino-contrib"
6
- s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
7
- s.email = "padrinorb@gmail.com"
8
- s.summary = "Contributed plugins and utilities for Padrino Framework"
9
- s.homepage = "http://www.padrinorb.com"
6
+ s.name = "padrino-contrib"
7
+ s.version = Padrino::Contrib::VERSION
8
+ s.authors = ["Davide D'Agostino", "Nathan Esquenazi", "Arthur Chiu"]
9
+ s.email = "padrinorb@gmail.com"
10
+ s.summary = "Contributed plugins and utilities for Padrino Framework"
11
+ s.homepage = "http://www.padrinorb.com"
10
12
  s.description = "Contributed plugins and utilities for the Padrino Ruby Web Framework"
11
- s.required_rubygems_version = ">= 1.3.6"
12
- s.version = Padrino::Contrib.version
13
- s.date = Time.now.strftime("%Y-%m-%d")
14
- s.extra_rdoc_files = Dir["*.rdoc"]
15
- s.files = %w(LICENSE README.rdoc Rakefile padrino-contrib.gemspec) + Dir.glob("{bin,lib,test}/**/*")
16
- s.rdoc_options = ["--charset=UTF-8"]
17
- s.require_path = "lib"
18
- end
13
+
14
+ s.rubyforge_project = "padrino-contrib"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Autoload' do
4
+
5
+ Dir[File.expand_path('./lib/**/*.rb')].each do |file|
6
+ next if file =~ /orm/ # orm extensions must be required by hand.
7
+ next if file =~ /padrino-contrib\.rb$/ # skip main file
8
+
9
+ klass = file.gsub(File.expand_path("./lib"), '').
10
+ gsub(/^\//, '').
11
+ gsub(/\.rb/, '').
12
+ gsub(/(^.)/) { $1.upcase }.
13
+ gsub(/\/|-/, "::").
14
+ gsub(/_(.)/) { $1.upcase }.
15
+ gsub(/::(.)/) { "::" + $1.upcase }.
16
+ gsub(/version/i, 'VERSION') # this is a constant
17
+
18
+ it(klass) { eval("#{klass}").should be_true }
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems' unless defined?(Gem)
2
+ require 'rspec' unless defined?(RSpec)
3
+ require 'padrino-contrib'
metadata CHANGED
@@ -1,24 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-contrib
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 6
10
- version: 0.0.6
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
- - Padrino Team
14
- - Nathan Esquenazi
15
13
  - Davide D'Agostino
14
+ - Nathan Esquenazi
16
15
  - Arthur Chiu
17
16
  autorequire:
18
17
  bindir: bin
19
18
  cert_chain: []
20
19
 
21
- date: 2011-04-04 00:00:00 +02:00
20
+ date: 2011-07-22 00:00:00 +02:00
22
21
  default_executable:
23
22
  dependencies: []
24
23
 
@@ -28,31 +27,36 @@ executables: []
28
27
 
29
28
  extensions: []
30
29
 
31
- extra_rdoc_files:
32
- - README.rdoc
30
+ extra_rdoc_files: []
31
+
33
32
  files:
33
+ - .gitignore
34
+ - Gemfile
34
35
  - LICENSE
35
36
  - README.rdoc
36
37
  - Rakefile
37
- - padrino-contrib.gemspec
38
+ - lib/padrino-contrib.rb
38
39
  - lib/padrino-contrib/auto_locale.rb
39
40
  - lib/padrino-contrib/exception_notifier.rb
40
41
  - lib/padrino-contrib/flash_session.rb
41
42
  - lib/padrino-contrib/helpers/assets_compressor.rb
42
- - lib/padrino-contrib/orm/ar/permalink.rb
43
- - lib/padrino-contrib/orm/ar/permalink_i18n.rb
44
- - lib/padrino-contrib/orm/ar/textile.rb
45
- - lib/padrino-contrib/orm/ar/translate.rb
46
- - lib/padrino-contrib/orm/mm/permalink.rb
47
- - lib/padrino-contrib/orm/mm/search.rb
43
+ - lib/padrino-contrib/orm/active_record/permalink.rb
44
+ - lib/padrino-contrib/orm/active_record/permalink_i18n.rb
45
+ - lib/padrino-contrib/orm/active_record/textile.rb
46
+ - lib/padrino-contrib/orm/active_record/translate.rb
47
+ - lib/padrino-contrib/orm/mongo_mapper/permalink.rb
48
+ - lib/padrino-contrib/orm/mongo_mapper/search.rb
48
49
  - lib/padrino-contrib/version.rb
50
+ - padrino-contrib.gemspec
51
+ - spec/autoload_spec.rb
52
+ - spec/spec_helper.rb
49
53
  has_rdoc: true
50
54
  homepage: http://www.padrinorb.com
51
55
  licenses: []
52
56
 
53
57
  post_install_message:
54
- rdoc_options:
55
- - --charset=UTF-8
58
+ rdoc_options: []
59
+
56
60
  require_paths:
57
61
  - lib
58
62
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -69,18 +73,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
73
  requirements:
70
74
  - - ">="
71
75
  - !ruby/object:Gem::Version
72
- hash: 23
76
+ hash: 3
73
77
  segments:
74
- - 1
75
- - 3
76
- - 6
77
- version: 1.3.6
78
+ - 0
79
+ version: "0"
78
80
  requirements: []
79
81
 
80
82
  rubyforge_project: padrino-contrib
81
- rubygems_version: 1.5.2
83
+ rubygems_version: 1.6.2
82
84
  signing_key:
83
85
  specification_version: 3
84
86
  summary: Contributed plugins and utilities for Padrino Framework
85
- test_files: []
86
-
87
+ test_files:
88
+ - spec/autoload_spec.rb
89
+ - spec/spec_helper.rb