hublot 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +15 -0
  2. data/{LICENSE.txt → MIT-LICENSE} +2 -4
  3. data/README.rdoc +42 -0
  4. data/Rakefile +34 -1
  5. data/lib/hublot.rb +1 -1
  6. data/lib/hublot/pretty.rb +16 -16
  7. data/lib/hublot/rails.rb +9 -0
  8. data/lib/hublot/version.rb +2 -2
  9. data/lib/tasks/hublot_tasks.rake +4 -0
  10. data/test/dummy/Guardfile +24 -0
  11. data/test/dummy/Rakefile +7 -0
  12. data/test/dummy/app/assets/javascripts/application.js +15 -0
  13. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  14. data/test/dummy/app/controllers/application_controller.rb +3 -0
  15. data/test/dummy/app/helpers/application_helper.rb +2 -0
  16. data/test/dummy/app/models/comment.rb +7 -0
  17. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  18. data/test/dummy/config.ru +4 -0
  19. data/test/dummy/config/application.rb +59 -0
  20. data/test/dummy/config/boot.rb +10 -0
  21. data/test/dummy/config/database.yml +25 -0
  22. data/test/dummy/config/environment.rb +5 -0
  23. data/test/dummy/config/environments/development.rb +37 -0
  24. data/test/dummy/config/environments/production.rb +67 -0
  25. data/test/dummy/config/environments/test.rb +37 -0
  26. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  27. data/test/dummy/config/initializers/inflections.rb +15 -0
  28. data/test/dummy/config/initializers/mime_types.rb +5 -0
  29. data/test/dummy/config/initializers/secret_token.rb +7 -0
  30. data/test/dummy/config/initializers/session_store.rb +8 -0
  31. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  32. data/test/dummy/config/locales/en.yml +5 -0
  33. data/test/dummy/config/routes.rb +58 -0
  34. data/test/dummy/db/development.sqlite3 +0 -0
  35. data/test/dummy/db/migrate/20130715211742_create_comments.rb +9 -0
  36. data/test/dummy/db/schema.rb +22 -0
  37. data/test/dummy/db/test.sqlite3 +0 -0
  38. data/test/dummy/log/development.log +57 -0
  39. data/test/dummy/log/test.log +3069 -0
  40. data/test/dummy/public/404.html +26 -0
  41. data/test/dummy/public/422.html +26 -0
  42. data/test/dummy/public/500.html +25 -0
  43. data/test/dummy/public/favicon.ico +0 -0
  44. data/test/dummy/script/rails +6 -0
  45. data/test/dummy/spec/factories.rb +86 -0
  46. data/test/dummy/spec/features/hublot_prettifies_time_with_zone_spec.rb +83 -0
  47. data/test/dummy/spec/models/comment_spec.rb +73 -0
  48. data/test/dummy/spec/spec_helper.rb +38 -0
  49. data/test/dummy/test/fixtures/comments.yml +7 -0
  50. data/test/dummy/test/unit/comment_test.rb +7 -0
  51. data/test/dummy/tmp/rspec_guard_result +1 -0
  52. data/test/hublot_test.rb +7 -0
  53. data/test/test_helper.rb +15 -0
  54. metadata +131 -57
  55. data/.gitignore +0 -17
  56. data/.rspec +0 -1
  57. data/Gemfile +0 -9
  58. data/README.md +0 -50
  59. data/hublot.gemspec +0 -24
  60. data/lib/clock/clockmanifest.rb +0 -17
  61. data/lib/clock/friday.rb +0 -9
  62. data/lib/clock/last_friday.rb +0 -9
  63. data/lib/clock/last_monday.rb +0 -9
  64. data/lib/clock/last_saturday.rb +0 -9
  65. data/lib/clock/last_sunday.rb +0 -9
  66. data/lib/clock/last_thursday.rb +0 -9
  67. data/lib/clock/last_tuesday.rb +0 -9
  68. data/lib/clock/last_wednesday.rb +0 -9
  69. data/lib/clock/monday.rb +0 -9
  70. data/lib/clock/next_monday.rb +0 -9
  71. data/lib/clock/next_sunday.rb +0 -9
  72. data/lib/clock/saturday.rb +0 -9
  73. data/lib/clock/sunday.rb +0 -9
  74. data/lib/clock/thursday.rb +0 -9
  75. data/lib/clock/timepiece.rb +0 -15
  76. data/lib/clock/tuesday.rb +0 -9
  77. data/lib/clock/wednesday.rb +0 -9
  78. data/lib/example_objects/active_record_example.rb +0 -14
  79. data/spec/clock_spec.rb +0 -119
  80. data/spec/pretty_spec.rb +0 -77
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWY2YWM0MTVlYzQ1NDE3MWVhY2YxY2I2ODNkN2M0N2U2NGNiMjQ2Yg==
5
+ data.tar.gz: !binary |-
6
+ OTNkNWMyYjNhMWY5N2FkZmIyZjNhNzU2MTRiZDIyODkwZDAwZDhlNw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MjYzMWU2NjMyMzkwNWJjNTRkZWVhMzhmOTRlYWJlNDA4MDJmNjU1N2NjN2E1
10
+ NGM0MGVlYjllYzBhMTVjZTRlOTIyYjM3MGYyYjgzZGJlYTQ0ZTY3YjczYmNk
11
+ NWE3Y2M5ZmMwMjg4Yzg3NTVlYWE1NmY2NjE1MzFkNjU5NzIxYjA=
12
+ data.tar.gz: !binary |-
13
+ MmUzMWY3MjczYzA4NTlkM2NlMWRjM2NlNzExMmY3NmY4YmYyN2M1MTE5Mjk5
14
+ MTExNWQ0YTYzY2IwZDJkODUyZTE0NjEzZjZjNTlmOTM2ZmIxOGRmNDZhZGZi
15
+ YjA2MGJlMzQzZjM0Nzk1M2ExN2M1OGI0M2IzMDVlNjgzZjk0MTU=
@@ -1,6 +1,4 @@
1
- Copyright (c) 2013 Brett Shollenberger
2
-
3
- MIT License
1
+ Copyright 2013 Brett Shollenberger
4
2
 
5
3
  Permission is hereby granted, free of charge, to any person obtaining
6
4
  a copy of this software and associated documentation files (the
@@ -19,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ = \Hublot
2
+
3
+ Hublot makes Facebook-style datetime-contextual datetimes a cinch for your ActiveRecord objects.
4
+
5
+ == Examples
6
+
7
+ ==== Comment created just now:
8
+
9
+ just now
10
+
11
+ ==== Comment created seconds or minutes ago
12
+
13
+ 10 seconds ago
14
+ 2 minutes ago
15
+
16
+ ==== Comment created today
17
+
18
+ Today at 5:30PM
19
+
20
+ ==== Comment created yesterday
21
+
22
+ Yesterday at 5:30PM
23
+
24
+ ==== Comment created this week
25
+
26
+ Monday at 5:30PM
27
+
28
+ ==== Comment created last week
29
+
30
+ Last Monday at 5:30PM
31
+
32
+ ==== After that:
33
+
34
+ Monday, July 1 at 5:30PM
35
+
36
+ == Use
37
+
38
+ gem "hublot", "~> 0.0.4"
39
+
40
+ Call the pretty method in your views:
41
+
42
+ <%= @comment.created_at.pretty %>
data/Rakefile CHANGED
@@ -1,2 +1,35 @@
1
- require 'bundler'
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Hublot'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
2
23
  Bundler::GemHelper.install_tasks
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+
35
+ task :default => :test
@@ -1,6 +1,6 @@
1
1
  require "hublot/version"
2
2
  require "hublot/pretty"
3
+ require "hublot/rails" if defined?(Rails)
3
4
 
4
5
  module Hublot
5
6
  end
6
-
@@ -2,10 +2,10 @@ module Hublot
2
2
 
3
3
  # Clock argument for testing; defaults to Time
4
4
  def pretty(clock=Time.now)
5
- @expired = (clock-self.created_at).to_i
5
+ @expired = (clock-self).to_i
6
6
  @today = clock.strftime('%A')
7
- @created = self.created_at.strftime('%A')
8
-
7
+ @created = self.to_time.strftime('%A')
8
+ # Require Rails date; test in irb Date::daynames
9
9
  @days = {
10
10
  "Monday" => 1,
11
11
  "Tuesday" => 2,
@@ -22,14 +22,14 @@ module Hublot
22
22
  return a_minute_ago if a_minute_ago?
23
23
  return minutes_ago if minutes_ago?
24
24
  return an_hour_ago if an_hour_ago?
25
- return today if today?
26
- return yesterday if yesterday?
25
+ return today if is_today?
26
+ return yesterday if is_yesterday?
27
27
  return this_week if this_week?
28
28
  return last_week if last_week?
29
29
  return datetimefiesta
30
30
  end
31
31
 
32
- protected
32
+ private
33
33
  def just_now
34
34
  'just now'
35
35
  end
@@ -79,27 +79,27 @@ protected
79
79
  end
80
80
 
81
81
  def today
82
- "Today at#{time}"
82
+ "Today at#{timeify}"
83
83
  end
84
84
 
85
- def time
86
- "#{self.created_at.strftime("%l:%M%p")}"
85
+ def timeify
86
+ "#{self.to_time.strftime("%l:%M%p")}"
87
87
  end
88
88
 
89
- def today?
89
+ def is_today?
90
90
  @days[@today] - @days[@created] == 0 && @expired >= 7200 && @expired <= 82800
91
91
  end
92
92
 
93
93
  def yesterday
94
- "Yesterday at #{time}"
94
+ "Yesterday at#{timeify}"
95
95
  end
96
96
 
97
- def yesterday?
97
+ def is_yesterday?
98
98
  (@days[@today] - @days[@created] == 1 || @days[@created] + @days[@today] == 8) && @expired <= 172800
99
99
  end
100
100
 
101
101
  def this_week
102
- "#{@created} at #{time}"
102
+ "#{@created} at#{timeify}"
103
103
  end
104
104
 
105
105
  def this_week?
@@ -107,14 +107,14 @@ protected
107
107
  end
108
108
 
109
109
  def last_week
110
- "Last #{@created} at #{time}"
110
+ "Last #{@created} at#{timeify}"
111
111
  end
112
112
 
113
113
  def last_week?
114
- @expired >= 518400 && @expired <= 1209600
114
+ @expired >= 518400 && @expired <= 1123200
115
115
  end
116
116
 
117
117
  def datetimefiesta
118
- self.created_at.strftime("%A, %B%e at %l:%M%p")
118
+ self.strftime("%A, %B %e at%l:%M%p")
119
119
  end
120
120
  end
@@ -0,0 +1,9 @@
1
+ require 'hublot'
2
+
3
+ module Hublot
4
+ class Rails < Rails::Railtie
5
+ initializer 'hublot.initialize' do
6
+ ActiveSupport::TimeWithZone.send :include, Hublot
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Hublot
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :hublot do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,7 @@
1
+ class Comment < ActiveRecord::Base
2
+ attr_accessible :body
3
+
4
+ def day_of_week
5
+ self.created_at.strftime('%A')
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "hublot"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Custom directories with classes and modules you want to be autoloadable.
15
+ # config.autoload_paths += %W(#{config.root}/extras)
16
+
17
+ # Only load the plugins named here, in the order given (default is alphabetical).
18
+ # :all can be used as a placeholder for all plugins not explicitly named.
19
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
+
21
+ # Activate observers that should always be running.
22
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
+
24
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
+ # config.time_zone = 'Central Time (US & Canada)'
27
+
28
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
+ # config.i18n.default_locale = :de
31
+
32
+ # Configure the default encoding used in templates for Ruby 1.9.
33
+ config.encoding = "utf-8"
34
+
35
+ # Configure sensitive parameters which will be filtered from the log file.
36
+ config.filter_parameters += [:password]
37
+
38
+ # Enable escaping HTML in JSON.
39
+ config.active_support.escape_html_entities_in_json = true
40
+
41
+ # Use SQL instead of Active Record's schema dumper when creating the database.
42
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
43
+ # like if you have constraints or database-specific column types
44
+ # config.active_record.schema_format = :sql
45
+
46
+ # Enforce whitelist mode for mass assignment.
47
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
48
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
49
+ # parameters by using an attr_accessible or attr_protected declaration.
50
+ config.active_record.whitelist_attributes = true
51
+
52
+ # Enable the asset pipeline
53
+ config.assets.enabled = true
54
+
55
+ # Version of your assets, change this if you want to expire all your assets
56
+ config.assets.version = '1.0'
57
+ end
58
+ end
59
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ config.active_record.mass_assignment_sanitizer = :strict
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ config.assets.compress = false
34
+
35
+ # Expands the lines which load the assets
36
+ config.assets.debug = true
37
+ end