mighty_grid 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0e08e21c7f221bea010b0122ccf6e2063ca5183b
4
+ data.tar.gz: 2a51d49c0f285e2a80ca07fa93e070f93d422588
5
+ SHA512:
6
+ metadata.gz: eb31c9ab5787ccf06f65f4c90db91cf0fbb5f5f768b4406c36a3fe3aba07437751fbb79139f52eacc86fb3a80bd87e70bdd32ff169b98b708f4060b82e6a7d1e
7
+ data.tar.gz: 71124468f6649987aca7fee50dc2fb9bf045298b2ff30a971d2bab67043df808c6c5a1d21fc91bbd64de901fe74769043ae51bfa78d2462cd779b911a3a80b59
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'rspec'
5
+ end
6
+
7
+ # Specify your gem's dependencies in flex_grid.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yury Snegirev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ 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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # MightyGrid
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mighty_grid'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mighty_grid
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/mighty_grid/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ module MightyGrid
2
+ class Column
3
+
4
+ attr_reader :display_property
5
+ attr_accessor :render_value, :attrs
6
+
7
+ def initialize(attr_or_options=nil, options=nil, &block)
8
+ @attrs = {}
9
+ if block_given?
10
+ @display_property = :block
11
+ @render_value = block
12
+ @attrs = attr_or_options[:html] if attr_or_options && attr_or_options.has_key?(:html)
13
+ else
14
+ @display_property = :attr
15
+ @render_value = attr_or_options
16
+ @attrs = options[:html] if options && options.has_key?(:html)
17
+ end
18
+ end
19
+
20
+ def render(record)
21
+ case @display_property
22
+ when :attr
23
+ return record[@render_value]
24
+ when :block
25
+ value = @render_value.call(record)
26
+ return ERB::Util.h(value).to_s.html_safe
27
+ else
28
+ # raise
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ module MightyGrid
2
+ class GridRenderer
3
+ attr_reader :columns, :th_columns
4
+
5
+ def initialize(grid, view)
6
+ @columns = []
7
+ @th_columns = []
8
+ end
9
+
10
+ def column(attr_or_options = {}, options=nil, &block)
11
+ if block_given?
12
+ options = attr_or_options.symbolize_keys
13
+ @th_columns << {title: options[:title], html: options[:th_html]}
14
+ @columns << MightyGrid::Column.new(options[:html], &block)
15
+ else
16
+ @columns << MightyGrid::Column.new(attr_or_options, options)
17
+ th_column = {title: attr_or_options.to_s.titleize}
18
+ th_column[:html] = options ? options[:th_html] : {}
19
+ @th_columns << th_column
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ module MightyGrid
2
+ module GridViewHelper
3
+ def grid(grid, opts={}, &block)
4
+ define_grid(grid, opts, &block)
5
+ render_grid(grid)
6
+ end
7
+
8
+ def define_grid(grid, options={}, &block)
9
+
10
+ rendering = GridRenderer.new(grid, self)
11
+
12
+ block.call(rendering)
13
+
14
+ table_html_attrs = options[:html] || {}
15
+ header_tr_html = options[:header_tr_html] || {}
16
+
17
+ grid.output_buffer = content_tag :table, table_html_attrs do
18
+ html = content_tag :thead do
19
+ content_tag :tr, header_tr_html do
20
+ rendering.th_columns.map{|column| content_tag :th, column[:title], column[:html]}.join.html_safe
21
+ end
22
+ end
23
+
24
+ html += content_tag :tbody do
25
+ html_record = ''
26
+ grid.relation.each do |rel|
27
+ html_record += content_tag :tr do
28
+ rendering.columns.map{|column| content_tag :td, column.render(rel), column.attrs}.join.html_safe
29
+ end
30
+ end
31
+ html_record.html_safe
32
+ end
33
+
34
+ html
35
+ end
36
+
37
+ end
38
+
39
+ def render_grid(grid)
40
+ grid.output_buffer.html_safe
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ module MightyGrid
2
+
3
+ module Controller
4
+
5
+ protected
6
+
7
+ attr_accessor :mighty_grid_instances
8
+
9
+ def init_grid(klass, opts={})
10
+ cg = MightyGrid::Base.new(klass, self, opts)
11
+ self.mighty_grid_instances = [] if self.mighty_grid_instances.nil?
12
+ self.mighty_grid_instances << cg
13
+ cg
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module MightyGrid
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'mighty_grid/version'
2
+ require 'mighty_grid/column'
3
+ require 'mighty_grid/grid_renderer'
4
+ require 'mighty_grid/helpers/mighty_grid_view_helpers'
5
+ require 'mighty_grid/mighty_grid_controller'
6
+
7
+ module MightyGrid
8
+ # Your code goes here...
9
+ class MightyGridEngine < ::Rails::Engine
10
+ initializer 'mighty_grid_railtie.configure_rails_initialization' do |app|
11
+
12
+ ActiveSupport.on_load :action_controller do
13
+ ActionController::Base.send(:include, MightyGrid::Controller)
14
+ end
15
+
16
+ ActiveSupport.on_load :action_view do
17
+ ::ActionView::Base.class_eval { include MightyGrid::GridViewHelper }
18
+ end
19
+
20
+ end
21
+ end
22
+
23
+ class Base
24
+
25
+ attr_reader :klass, :relation
26
+
27
+ attr_accessor :output_buffer
28
+
29
+ def initialize(klass_or_relation, controller, opts = {}) #:nodoc:
30
+ @controller = controller
31
+
32
+ @relation = klass_or_relation
33
+
34
+ @klass = klass_or_relation.is_a?(ActiveRecord::Relation) ? klass_or_relation.klass : klass_or_relation
35
+
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mighty_grid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mighty_grid"
8
+ spec.version = MightyGrid::VERSION
9
+ spec.authors = ["jurrick"]
10
+ spec.email = ["jurianp@gmail.com"]
11
+ spec.summary = %q{Flexible grid for Rails}
12
+ spec.description = %q{Flexible grid for Rails}
13
+ spec.homepage = "http://github.com/jurrick/mighty_grid"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mighty_grid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - jurrick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Flexible grid for Rails
42
+ email:
43
+ - jurianp@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/mighty_grid.rb
55
+ - lib/mighty_grid/column.rb
56
+ - lib/mighty_grid/grid_renderer.rb
57
+ - lib/mighty_grid/helpers/mighty_grid_view_helpers.rb
58
+ - lib/mighty_grid/mighty_grid_controller.rb
59
+ - lib/mighty_grid/version.rb
60
+ - mighty_grid.gemspec
61
+ - spec/spec_helper.rb
62
+ homepage: http://github.com/jurrick/mighty_grid
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.1
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Flexible grid for Rails
86
+ test_files:
87
+ - spec/spec_helper.rb
88
+ has_rdoc: