rails_view_helpers 0.0.1 → 0.0.2

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.
data/README.md CHANGED
@@ -1,3 +1,29 @@
1
1
  # RailsViewHelpers
2
2
 
3
- [API documentation](http://rubydoc.info/gems/rails_view_helpers/frames/file/README.md)
3
+ [![Gem Version](https://badge.fury.io/rb/rails_view_helpers.png)](http://badge.fury.io/rb/rails_view_helpers)
4
+ [![Build Status](https://travis-ci.org/stevedowney/rails_view_helpers.png)](https://travis-ci.org/stevedowney/rails_view_helpers)
5
+ [![Code Climate](https://codeclimate.com/github/stevedowney/rails_view_helpers.png)](https://codeclimate.com/github/stevedowney/rails_view_helpers)
6
+ [![Coverage Status](https://coveralls.io/repos/stevedowney/rails_view_helpers/badge.png?branch=master)](https://coveralls.io/r/stevedowney/rails_view_helpers?branch=master)
7
+
8
+ ## Documentation
9
+ [API documentation](http://rubydoc.info/gems/rails_view_helpers/frames/file/README.md)
10
+
11
+ ## Installation
12
+
13
+ Add it to your Gemfile:
14
+
15
+ ```ruby
16
+ gem "rails_view_helpers"
17
+ ```
18
+
19
+ Run bundler:
20
+
21
+ ```sh
22
+ bundle install
23
+ ```
24
+
25
+ Run generator:
26
+
27
+ ```sh
28
+ rails g rails_view_helpers:install
29
+ ```
@@ -0,0 +1,28 @@
1
+ module RailsViewHelpers
2
+
3
+ # Date and Datetime related view helpers.
4
+
5
+ module DatetimeHelper
6
+
7
+ # Return _date_or_datetime_ converted to _format_.
8
+ #
9
+ # Reminder:
10
+ # * you can add formats (e.g. in an initializer)
11
+ # * this gem has monkey-patched +NilClass+ so you can just do this: +datetime.to_s(:short)+ without worrying if +datetime+ is +nil+.
12
+ #
13
+ # @example
14
+ # datetime_to_s(record.created_at, :long)
15
+ # datetime_to_s(Date.today, :short)
16
+ # @param date_or_datetime [Date, Datetime] the date/time to convert to string
17
+ # @param format [Symbol] one of +Date::DATE_FORMATS+ or +Time::DATE_FORMATS+
18
+ # @return [String]
19
+ def datetime_to_s(date_or_datetime, format)
20
+ return '' if date_or_datetime.blank?
21
+ return date_or_datetime.to_s(format) if date_or_datetime.instance_of?(Date)
22
+ date_or_datetime.localtime.to_s(format)
23
+ end
24
+
25
+
26
+ end
27
+
28
+ end
@@ -8,6 +8,8 @@ module RailsViewHelpers
8
8
  # body_tag() #=> <body data-action='index' data-controller='home'>
9
9
  #
10
10
  # body_tag(id: 'my-id', class: 'my-class') #=> <body class="my-class" data-action="index" data-controller="home" id="my-id">
11
+ # @param options [Hash] become attributes of the BODY tag
12
+ # @return [String]
11
13
  def body_tag(options={}, &block)
12
14
  options = canonicalize_options(options)
13
15
  options.delete(:class) if options[:class].blank?
@@ -38,6 +40,11 @@ module RailsViewHelpers
38
40
  end
39
41
  end
40
42
 
43
+ # Same as +bln+ but wrapped in a TD and centered (w/rail_view_helper.css)
44
+ #
45
+ # @example
46
+ # td_bln(true) #=> <td class="c">&#10004;</td>
47
+ # @return [String]
41
48
  def td_bln(*args)
42
49
  options = canonicalize_options(args.extract_options!)
43
50
  options = ensure_class(options, 'c')
@@ -45,6 +52,17 @@ module RailsViewHelpers
45
52
  content_tag(:td, bln(*args), options)
46
53
  end
47
54
 
55
+
56
+ def th_actions(*args)
57
+ options = canonicalize_options(args.extract_options!)
58
+ colspan = args.shift || 1
59
+ text = args.shift || 'Actions'
60
+ options[:colspan] = colspan
61
+ options[:class] = 'c' if options[:class].empty?
62
+
63
+ content_tag(:th, text, options)
64
+ end
65
+
48
66
  # Returns one or more non-breaking spaces (&nbsp;) marked +html_safe+.
49
67
  #
50
68
  # @example
@@ -0,0 +1,17 @@
1
+ module RailsViewHelpers
2
+
3
+ module JavascriptHelper
4
+
5
+ # Convenience method for +javascript:void(0)+
6
+ #
7
+ # @example
8
+ # js_void #=> "javascript:void(0)"
9
+ #
10
+ # @return [String]
11
+ def js_void
12
+ @_js_void ||= "javascript:void(0)"
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails/generators/active_record/migration'
2
+
3
+ module RailsViewHelpers
4
+ # @private
5
+ module Generators
6
+ # @private
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.join(File.dirname(__FILE__), "templates")
9
+
10
+ desc 'Copy rails_view_helpers files'
11
+
12
+ def install
13
+ directory 'app/assets'
14
+ directory 'config'
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ th.c, td.c {
2
+ text-align: center;
3
+ }
@@ -0,0 +1,21 @@
1
+ class NilClass
2
+
3
+ # This hack enables us to call +to_s+ on a (supposedly) Date/Datetime
4
+ # with out worrying that the value may be +nil+.
5
+ #
6
+ # @return [String]
7
+ def to_s(*args)
8
+ return super unless args.length == 1
9
+
10
+ format = args.first
11
+ return super unless known_formats.include?(format)
12
+
13
+ return ''
14
+ end
15
+
16
+ private
17
+
18
+ def known_formats
19
+ @known_formats ||= Date::DATE_FORMATS + Time::DATE_FORMATS
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsViewHelpers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_view_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-14 00:00:00.000000000 Z
12
+ date: 2013-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -259,8 +259,13 @@ extensions: []
259
259
  extra_rdoc_files: []
260
260
  files:
261
261
  - app/helpers/rails_view_helpers/common_helper.rb
262
+ - app/helpers/rails_view_helpers/datetime_helper.rb
262
263
  - app/helpers/rails_view_helpers/html_helper.rb
264
+ - app/helpers/rails_view_helpers/javascript_helper.rb
263
265
  - config/routes.rb
266
+ - lib/generators/rails_view_helpers/install_generator.rb
267
+ - lib/generators/rails_view_helpers/templates/app/assets/stylesheets/rails_view_helpers.css
268
+ - lib/generators/rails_view_helpers/templates/config/initializers/local/core-extensions/nil_class.rb
264
269
  - lib/rails_view_helpers/engine.rb
265
270
  - lib/rails_view_helpers/version.rb
266
271
  - lib/rails_view_helpers.rb
@@ -280,18 +285,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
280
285
  - - ! '>='
281
286
  - !ruby/object:Gem::Version
282
287
  version: '0'
283
- segments:
284
- - 0
285
- hash: -3460792648407326703
286
288
  required_rubygems_version: !ruby/object:Gem::Requirement
287
289
  none: false
288
290
  requirements:
289
291
  - - ! '>='
290
292
  - !ruby/object:Gem::Version
291
293
  version: '0'
292
- segments:
293
- - 0
294
- hash: -3460792648407326703
295
294
  requirements: []
296
295
  rubyforge_project:
297
296
  rubygems_version: 1.8.25