tabledata-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16f70a237729234493cabbbbcf9fe579841bde0e
4
+ data.tar.gz: 0d7730abfc3e0bc4e4ecad256ea4b178463f359a
5
+ SHA512:
6
+ metadata.gz: 1c5aa504adeb12bc18d6888bcbb00934cfe9a757ddc0ae9119780d71d144d6bd3aab5fba8275ff09ef799232aca902feb06b67b1ffdb0e4d341bcb032dc80c36
7
+ data.tar.gz: 990b1a53455c04c1b777cfdcff729e67767b11627c0671bdc7cfd1b91c8b74496a65ede5507808e31fe34f9952633fe2c12c934e88be8c6a8cb51e6ccab88ebf
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Roman Simecek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Tabledata::Rails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tabledata/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tabledata-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tabledata-rails
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tabledata-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tabledata/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ require "tabledata/rails/view_helpers"
2
+
3
+ module Tabledata
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ initializer "tabledata-rails.view_helpers" do
7
+ ActionView::Base.send(:include, Tabledata::Rails::ViewHelpers)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Tabledata
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,112 @@
1
+ module Tabledata
2
+ module Rails
3
+ module ViewHelpers
4
+ def render_tabledata(table, i18n_scope: nil)
5
+ content_tag(:table, class: "table table-striped".freeze) {
6
+ concat(
7
+ content_tag(:thead) {
8
+ content_tag(:tr) {
9
+
10
+ table.headers.each_with_index { |header_name, index|
11
+ next unless is_column_displayed?(table.column_definition(index))
12
+
13
+ concat(
14
+ content_tag(
15
+ :th,
16
+ t(
17
+ i18n_head_key(
18
+ table.column_definition(index).accessor,
19
+ i18n_scope
20
+ )
21
+ ),
22
+ class: ["tabledata-header", table.column_definition(index).accessor],
23
+ )
24
+ )
25
+ }
26
+ }
27
+ }
28
+ ).concat(
29
+ content_tag(:tbody) {
30
+ table.body.each { |row|
31
+ concat(
32
+ content_tag(:tr) {
33
+ row.present(:view).each_with_index { |column, index|
34
+ column_definition = table.column_definition(index)
35
+ next unless is_column_displayed?(column_definition)
36
+
37
+ concat(
38
+ content_tag(:td, class: error_classes(row, column_definition)) {
39
+ concat(column)
40
+ concat(
41
+ content_tag(
42
+ :i,
43
+ "".freeze,
44
+ class: "error-hint icon-info-sign alert".freeze,
45
+ data: {toggle: "tooltip".freeze, html: true},
46
+ title: error_text(row, column_definition, i18n_scope),
47
+ )
48
+ ) if column_has_error?(row, column_definition)
49
+ }
50
+ )
51
+ }
52
+ }
53
+ )
54
+ }
55
+ }
56
+ )
57
+ }
58
+ end
59
+
60
+ private
61
+
62
+ def error_text(row, column_definition, i18n_scope)
63
+ error_texts = []
64
+ accessor = column_definition.accessor
65
+
66
+ row.column_errors[accessor].each do |key, options|
67
+ error_texts << t(i18n_error_key(accessor, key, i18n_scope), options)
68
+ end
69
+
70
+ error_texts.join("<br />".freeze)
71
+ end
72
+
73
+ def i18n_head_key(column_name, i18n_scope)
74
+ [
75
+ i18n_scope,
76
+ ".".freeze,
77
+ "tabledata".freeze,
78
+ ".".freeze,
79
+ "header".freeze,
80
+ ".".freeze,
81
+ column_name
82
+ ].compact!.join
83
+ end
84
+
85
+ def i18n_error_key(column_name, key, i18n_scope)
86
+ [
87
+ i18n_scope,
88
+ ".".freeze,
89
+ "tabledata".freeze,
90
+ ".".freeze,
91
+ "column_errors".freeze,
92
+ ".".freeze,
93
+ column_name,
94
+ ".".freeze,
95
+ key.to_s
96
+ ].compact!.join
97
+ end
98
+
99
+ def column_has_error?(row, column_definition)
100
+ row.column_errors.has_key?(column_definition.accessor)
101
+ end
102
+
103
+ def error_classes(row, column_definition)
104
+ column_has_error?(row, column_definition) ? "error".freeze : "success".freeze
105
+ end
106
+
107
+ def is_column_displayed?(column_definition)
108
+ column_definition.options.fetch(:html, {display: true})[:display]
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,2 @@
1
+ require "tabledata/rails/version"
2
+ require "tabledata/rails/railtie" if defined?(Rails)
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tabledata/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tabledata-rails"
8
+ spec.version = Tabledata::Rails::VERSION
9
+ spec.authors = ["Roman Simecek"]
10
+ spec.email = ["roman@good2go.ch"]
11
+
12
+ spec.summary = %q{Rails view helpers for tabledata gem.}
13
+ spec.homepage = "http://github.com/raskhadafi/tabledata-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files =
17
+ Dir['bin/**/*'] +
18
+ Dir['lib/**/*'] +
19
+ Dir['rake/**/*'] +
20
+ Dir['test/**/*'] +
21
+ Dir['*.gemspec'] +
22
+ %w[
23
+ LICENSE.txt
24
+ Rakefile
25
+ README.md
26
+ CODE_OF_CONDUCT.md
27
+ ]
28
+
29
+ spec.bindir = "exe"
30
+
31
+ if File.directory?("exe") then
32
+ s.executables = Dir.chdir("exe") {
33
+ Dir.glob('**/*').select { |f| File.executable?(f) }
34
+ }
35
+ end
36
+
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_runtime_dependency "tabledata"
40
+ spec.add_runtime_dependency "rails"
41
+
42
+ spec.add_development_dependency "bundler", "~> 1.10"
43
+ spec.add_development_dependency "rake", "~> 10.0"
44
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tabledata-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roman Simecek
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tabledata
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - roman@good2go.ch
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CODE_OF_CONDUCT.md
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - bin/console
81
+ - bin/setup
82
+ - lib/tabledata/rails.rb
83
+ - lib/tabledata/rails/railtie.rb
84
+ - lib/tabledata/rails/version.rb
85
+ - lib/tabledata/rails/view_helpers.rb
86
+ - tabledata-rails.gemspec
87
+ homepage: http://github.com/raskhadafi/tabledata-rails
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.8
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Rails view helpers for tabledata gem.
111
+ test_files: []
112
+ has_rdoc: