mighty_grid 0.0.2 → 0.0.3
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 +4 -4
- data/app/views/kaminari/mighty_grid/_first_page.html.erb +0 -0
- data/app/views/kaminari/mighty_grid/_gap.html.erb +3 -0
- data/app/views/kaminari/mighty_grid/_last_page.html.erb +0 -0
- data/app/views/kaminari/mighty_grid/_next_page.html.erb +3 -0
- data/app/views/kaminari/mighty_grid/_page.html.erb +3 -0
- data/app/views/kaminari/mighty_grid/_paginator.html.erb +15 -0
- data/app/views/kaminari/mighty_grid/_prev_page.html.erb +3 -0
- data/lib/mighty_grid.rb +46 -3
- data/lib/mighty_grid/column.rb +11 -4
- data/lib/mighty_grid/grid_renderer.rb +11 -7
- data/lib/mighty_grid/helpers/mighty_grid_view_helpers.rb +26 -1
- data/lib/mighty_grid/kaminari_monkey_patching.rb +13 -0
- data/lib/mighty_grid/mighty_grid_ext.rb +21 -0
- data/lib/mighty_grid/version.rb +1 -1
- data/mighty_grid.gemspec +2 -0
- data/vendor/assets/stylesheets/mighty_grid.css +3 -0
- metadata +26 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7d3d1e2a4aa491cd41cb2ab49f395647aa281538
         | 
| 4 | 
            +
              data.tar.gz: 08344ab81f0419c86511071fea30144dc21ba192
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7f4025181acf0ca7074b0c55fc9a12e2b065f4352019e0806cecb1bc27b418f12a3a811067b834feb7c88802d63934f85f826b96d53c6426db8f7d95f79b3f51
         | 
| 7 | 
            +
              data.tar.gz: e0fba9c3e9be9f0c641dce7c03e5d67688efd01f1c83f710f1e35f5cf932935210f4842b93cb782653ee7722f73c0f6ae3a087d962b647f36f65d47cd2d6ec31
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            <%= paginator.render do -%>
         | 
| 2 | 
            +
                <ul class="pagination pagination-sm pull-right">
         | 
| 3 | 
            +
                  <%= first_page_tag unless current_page.first? %>
         | 
| 4 | 
            +
                  <%= prev_page_tag unless current_page.first? %>
         | 
| 5 | 
            +
                  <% each_page do |page| -%>
         | 
| 6 | 
            +
                    <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
         | 
| 7 | 
            +
                      <%= page_tag page %>
         | 
| 8 | 
            +
                    <% elsif !page.was_truncated? -%>
         | 
| 9 | 
            +
                      <%= gap_tag %>
         | 
| 10 | 
            +
                    <% end -%>
         | 
| 11 | 
            +
                  <% end -%>
         | 
| 12 | 
            +
                  <%= next_page_tag unless current_page.last? %>
         | 
| 13 | 
            +
                  <%= last_page_tag unless current_page.last? %>
         | 
| 14 | 
            +
                </ul>
         | 
| 15 | 
            +
            <% end -%>
         | 
    
        data/lib/mighty_grid.rb
    CHANGED
    
    | @@ -1,11 +1,14 @@ | |
| 1 1 | 
             
            require 'mighty_grid/version'
         | 
| 2 | 
            +
            require 'mighty_grid/mighty_grid_ext'
         | 
| 2 3 | 
             
            require 'mighty_grid/column'
         | 
| 3 4 | 
             
            require 'mighty_grid/grid_renderer'
         | 
| 4 5 | 
             
            require 'mighty_grid/helpers/mighty_grid_view_helpers'
         | 
| 5 6 | 
             
            require 'mighty_grid/mighty_grid_controller'
         | 
| 6 7 |  | 
| 8 | 
            +
            require 'kaminari.rb'
         | 
| 9 | 
            +
             | 
| 7 10 | 
             
            module MightyGrid
         | 
| 8 | 
            -
             | 
| 11 | 
            +
             | 
| 9 12 | 
             
              class MightyGridEngine < ::Rails::Engine
         | 
| 10 13 | 
             
                initializer 'mighty_grid_railtie.configure_rails_initialization' do |app|
         | 
| 11 14 |  | 
| @@ -15,6 +18,9 @@ module MightyGrid | |
| 15 18 |  | 
| 16 19 | 
             
                  ActiveSupport.on_load :action_view do
         | 
| 17 20 | 
             
                    ::ActionView::Base.class_eval { include MightyGrid::GridViewHelper }
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    # It is here only until this pull request is pulled: https://github.com/amatsuda/kaminari/pull/267
         | 
| 23 | 
            +
                    require 'mighty_grid/kaminari_monkey_patching'
         | 
| 18 24 | 
             
                  end
         | 
| 19 25 |  | 
| 20 26 | 
             
                end
         | 
| @@ -22,18 +28,55 @@ module MightyGrid | |
| 22 28 |  | 
| 23 29 | 
             
              class Base
         | 
| 24 30 |  | 
| 25 | 
            -
                attr_reader :klass, :relation
         | 
| 26 | 
            -
             | 
| 31 | 
            +
                attr_reader :klass, :name, :relation, :options, :mg_params
         | 
| 27 32 | 
             
                attr_accessor :output_buffer
         | 
| 28 33 |  | 
| 29 34 | 
             
                def initialize(klass_or_relation, controller, opts = {})  #:nodoc:
         | 
| 30 35 | 
             
                  @controller = controller
         | 
| 31 36 |  | 
| 37 | 
            +
                  @options = {
         | 
| 38 | 
            +
                    page: 1,
         | 
| 39 | 
            +
                    per_page: 10,
         | 
| 40 | 
            +
                    name: 'grid'
         | 
| 41 | 
            +
                  }
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  opts.assert_valid_keys(@options.keys)
         | 
| 44 | 
            +
                  @options.merge!(opts)
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  @name = @options[:name].to_s
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  load_grid_params
         | 
| 49 | 
            +
             | 
| 32 50 | 
             
                  @relation = klass_or_relation
         | 
| 33 51 |  | 
| 34 52 | 
             
                  @klass = klass_or_relation.is_a?(ActiveRecord::Relation) ? klass_or_relation.klass : klass_or_relation
         | 
| 35 53 |  | 
| 36 54 | 
             
                end
         | 
| 37 55 |  | 
| 56 | 
            +
                def read
         | 
| 57 | 
            +
                  @relation = @relation.order(@mg_params[:order] => @mg_params[:order_direction].to_sym) if @mg_params[:order].present? && @mg_params[:order_direction].present?
         | 
| 58 | 
            +
                  @relation = @relation.page(@mg_params[:page]).per(@mg_params[:per_page])
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                def params
         | 
| 62 | 
            +
                  @controller.params
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                def load_grid_params
         | 
| 66 | 
            +
                  @mg_params = {}
         | 
| 67 | 
            +
                  @mg_params.merge!(@options)
         | 
| 68 | 
            +
                  if current_grid_params
         | 
| 69 | 
            +
                    @mg_params.merge!(current_grid_params.symbolize_keys)
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                def current_grid_params
         | 
| 74 | 
            +
                  params[name] || {}
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                def order_direction
         | 
| 78 | 
            +
                  (current_grid_params.has_key?('order_direction')) ? (['asc', 'desc'] - [current_grid_params['order_direction']]).first : 'asc'
         | 
| 79 | 
            +
                end
         | 
| 80 | 
            +
             | 
| 38 81 | 
             
              end
         | 
| 39 82 | 
             
            end
         | 
    
        data/lib/mighty_grid/column.rb
    CHANGED
    
    | @@ -1,19 +1,26 @@ | |
| 1 1 | 
             
            module MightyGrid
         | 
| 2 2 | 
             
              class Column
         | 
| 3 3 |  | 
| 4 | 
            -
                attr_reader :display_property
         | 
| 5 | 
            -
                attr_accessor :render_value | 
| 4 | 
            +
                attr_reader :display_property, :attribute, :attrs, :th_attrs, :options, :title
         | 
| 5 | 
            +
                attr_accessor :render_value
         | 
| 6 6 |  | 
| 7 7 | 
             
                def initialize(attr_or_options=nil, options=nil, &block)
         | 
| 8 8 | 
             
                  @attrs = {}
         | 
| 9 9 | 
             
                  if block_given?
         | 
| 10 | 
            +
                    @options = attr_or_options
         | 
| 10 11 | 
             
                    @display_property = :block
         | 
| 11 12 | 
             
                    @render_value = block
         | 
| 12 | 
            -
                    @attrs =  | 
| 13 | 
            +
                    @attrs = options[:html] if options && options.has_key?(:html)
         | 
| 14 | 
            +
                    @th_attrs = options[:th_html] if options && options.has_key?(:th_html)
         | 
| 15 | 
            +
                    @title = options[:title] || ''
         | 
| 13 16 | 
             
                  else
         | 
| 17 | 
            +
                    @options = options
         | 
| 18 | 
            +
                    @attribute = attr_or_options
         | 
| 14 19 | 
             
                    @display_property = :attr
         | 
| 15 | 
            -
                    @render_value =  | 
| 20 | 
            +
                    @render_value = attribute
         | 
| 16 21 | 
             
                    @attrs = options[:html] if options && options.has_key?(:html)
         | 
| 22 | 
            +
                    @th_attrs = options[:th_html] if options && options.has_key?(:th_html)
         | 
| 23 | 
            +
                    @title = options[:title] || ''
         | 
| 17 24 | 
             
                  end
         | 
| 18 25 | 
             
                end
         | 
| 19 26 |  | 
| @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            module MightyGrid
         | 
| 2 2 | 
             
              class GridRenderer
         | 
| 3 | 
            -
                attr_reader :columns, :th_columns
         | 
| 3 | 
            +
                attr_reader :columns, :th_columns, :total_columns
         | 
| 4 4 |  | 
| 5 5 | 
             
                def initialize(grid, view)
         | 
| 6 6 | 
             
                  @columns = []
         | 
| @@ -10,14 +10,18 @@ module MightyGrid | |
| 10 10 | 
             
                def column(attr_or_options = {}, options=nil, &block)
         | 
| 11 11 | 
             
                  if block_given?
         | 
| 12 12 | 
             
                    options = attr_or_options.symbolize_keys
         | 
| 13 | 
            -
                    @ | 
| 14 | 
            -
                    @columns << MightyGrid::Column.new(options[:html], &block)
         | 
| 13 | 
            +
                    @columns << MightyGrid::Column.new(options, &block)
         | 
| 15 14 | 
             
                  else
         | 
| 16 | 
            -
                     | 
| 17 | 
            -
                     | 
| 18 | 
            -
                     | 
| 19 | 
            -
             | 
| 15 | 
            +
                    attribute = attr_or_options.to_sym
         | 
| 16 | 
            +
                    options = {} unless options.is_a?(Hash)
         | 
| 17 | 
            +
                    opts = {
         | 
| 18 | 
            +
                      title: attr_or_options.to_s.titleize,
         | 
| 19 | 
            +
                      ordering: true,
         | 
| 20 | 
            +
                      attribute: attribute
         | 
| 21 | 
            +
                    }.merge!(options)
         | 
| 22 | 
            +
                    @columns << MightyGrid::Column.new(attribute, opts)
         | 
| 20 23 | 
             
                  end
         | 
| 24 | 
            +
                  @total_columns = @columns.count
         | 
| 21 25 | 
             
                end
         | 
| 22 26 | 
             
              end
         | 
| 23 27 | 
             
            end
         | 
| @@ -12,15 +12,39 @@ module MightyGrid | |
| 12 12 | 
             
                  block.call(rendering)
         | 
| 13 13 |  | 
| 14 14 | 
             
                  table_html_attrs = options[:html] || {}
         | 
| 15 | 
            +
                  table_html_attrs[:class] += ' mighty-grid'
         | 
| 16 | 
            +
             | 
| 15 17 | 
             
                  header_tr_html = options[:header_tr_html] || {}
         | 
| 16 18 |  | 
| 19 | 
            +
                  grid.read
         | 
| 20 | 
            +
             | 
| 17 21 | 
             
                  grid.output_buffer = content_tag :table, table_html_attrs do
         | 
| 18 22 | 
             
                    html = content_tag :thead do
         | 
| 19 23 | 
             
                      content_tag :tr, header_tr_html do
         | 
| 20 | 
            -
                        rendering. | 
| 24 | 
            +
                        rendering.columns.map { |column|
         | 
| 25 | 
            +
                          content_tag :th, column.th_attrs do
         | 
| 26 | 
            +
                            if column.options[:ordering]
         | 
| 27 | 
            +
                              link_to(column.title, "?#{MightyGrid::MgHash.rec_merge(grid.params, {grid.name => {order: column.attribute, order_direction: grid.order_direction}}).except('controller', 'action').to_query}").html_safe
         | 
| 28 | 
            +
                            else
         | 
| 29 | 
            +
                              column.title.html_safe
         | 
| 30 | 
            +
                            end
         | 
| 31 | 
            +
                          end
         | 
| 32 | 
            +
                        }.join.html_safe
         | 
| 21 33 | 
             
                      end
         | 
| 22 34 | 
             
                    end
         | 
| 23 35 |  | 
| 36 | 
            +
                    html += content_tag :tfoot do
         | 
| 37 | 
            +
                      html_record = content_tag :tr do
         | 
| 38 | 
            +
                        content_tag :td, colspan: rendering.total_columns do
         | 
| 39 | 
            +
                          html_pag = paginate(grid.relation, theme: 'mighty_grid', param_name: "#{grid.name}[page]")
         | 
| 40 | 
            +
                          html_pag += page_entries_info(grid.relation)
         | 
| 41 | 
            +
                          html_pag.html_safe
         | 
| 42 | 
            +
                        end
         | 
| 43 | 
            +
                      end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                      html_record.html_safe
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
             | 
| 24 48 | 
             
                    html += content_tag :tbody do
         | 
| 25 49 | 
             
                      html_record = ''
         | 
| 26 50 | 
             
                      grid.relation.each do |rel|
         | 
| @@ -39,5 +63,6 @@ module MightyGrid | |
| 39 63 | 
             
                def render_grid(grid)
         | 
| 40 64 | 
             
                  grid.output_buffer.html_safe
         | 
| 41 65 | 
             
                end
         | 
| 66 | 
            +
             | 
| 42 67 | 
             
              end
         | 
| 43 68 | 
             
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
            # It is here only until this pull request is pulled: https://github.com/amatsuda/kaminari/pull/267
         | 
| 3 | 
            +
            module Kaminari #:nodoc:
         | 
| 4 | 
            +
              module Helpers #:nodoc:
         | 
| 5 | 
            +
                class Tag #:nodoc:
         | 
| 6 | 
            +
                  def page_url_for(page) #:nodoc:
         | 
| 7 | 
            +
                    current_page_params_as_query_string = @param_name.to_s + '=' + (page <= 1 ? nil : page).to_s
         | 
| 8 | 
            +
                    current_page_params_as_hash = Rack::Utils.parse_nested_query(current_page_params_as_query_string)
         | 
| 9 | 
            +
                    @template.url_for MightyGrid::MgHash.rec_merge(@params, current_page_params_as_hash).symbolize_keys
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module MightyGrid
         | 
| 2 | 
            +
              module MgHash
         | 
| 3 | 
            +
                class << self
         | 
| 4 | 
            +
                	# A deep merge of two hashes.
         | 
| 5 | 
            +
                  # That is, if both hashes have the same key and the values are hashes, these two hashes should also be merged.
         | 
| 6 | 
            +
                  # Used for merging two sets of params.
         | 
| 7 | 
            +
                  def rec_merge(hash, other)  #:nodoc:
         | 
| 8 | 
            +
                    res = hash.clone
         | 
| 9 | 
            +
                    other.each do |key, other_value|
         | 
| 10 | 
            +
                      value = res[key]
         | 
| 11 | 
            +
                      if value.is_a?(Hash) && other_value.is_a?(Hash)
         | 
| 12 | 
            +
                        res[key] = rec_merge value, other_value
         | 
| 13 | 
            +
                      else
         | 
| 14 | 
            +
                        res[key] = other_value
         | 
| 15 | 
            +
                      end
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                    res
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
    
        data/lib/mighty_grid/version.rb
    CHANGED
    
    
    
        data/mighty_grid.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mighty_grid
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - jurrick
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-04- | 
| 11 | 
            +
            date: 2014-04-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -38,6 +38,20 @@ dependencies: | |
| 38 38 | 
             
                - - ">="
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: kaminari
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: 0.15.0
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 0.15.0
         | 
| 41 55 | 
             
            description: Flexible grid for Rails
         | 
| 42 56 | 
             
            email:
         | 
| 43 57 | 
             
            - jurianp@gmail.com
         | 
| @@ -51,14 +65,24 @@ files: | |
| 51 65 | 
             
            - LICENSE.txt
         | 
| 52 66 | 
             
            - README.md
         | 
| 53 67 | 
             
            - Rakefile
         | 
| 68 | 
            +
            - app/views/kaminari/mighty_grid/_first_page.html.erb
         | 
| 69 | 
            +
            - app/views/kaminari/mighty_grid/_gap.html.erb
         | 
| 70 | 
            +
            - app/views/kaminari/mighty_grid/_last_page.html.erb
         | 
| 71 | 
            +
            - app/views/kaminari/mighty_grid/_next_page.html.erb
         | 
| 72 | 
            +
            - app/views/kaminari/mighty_grid/_page.html.erb
         | 
| 73 | 
            +
            - app/views/kaminari/mighty_grid/_paginator.html.erb
         | 
| 74 | 
            +
            - app/views/kaminari/mighty_grid/_prev_page.html.erb
         | 
| 54 75 | 
             
            - lib/mighty_grid.rb
         | 
| 55 76 | 
             
            - lib/mighty_grid/column.rb
         | 
| 56 77 | 
             
            - lib/mighty_grid/grid_renderer.rb
         | 
| 57 78 | 
             
            - lib/mighty_grid/helpers/mighty_grid_view_helpers.rb
         | 
| 79 | 
            +
            - lib/mighty_grid/kaminari_monkey_patching.rb
         | 
| 58 80 | 
             
            - lib/mighty_grid/mighty_grid_controller.rb
         | 
| 81 | 
            +
            - lib/mighty_grid/mighty_grid_ext.rb
         | 
| 59 82 | 
             
            - lib/mighty_grid/version.rb
         | 
| 60 83 | 
             
            - mighty_grid.gemspec
         | 
| 61 84 | 
             
            - spec/spec_helper.rb
         | 
| 85 | 
            +
            - vendor/assets/stylesheets/mighty_grid.css
         | 
| 62 86 | 
             
            homepage: http://github.com/jurrick/mighty_grid
         | 
| 63 87 | 
             
            licenses:
         | 
| 64 88 | 
             
            - MIT
         | 
| @@ -85,4 +109,3 @@ specification_version: 4 | |
| 85 109 | 
             
            summary: Flexible grid for Rails
         | 
| 86 110 | 
             
            test_files:
         | 
| 87 111 | 
             
            - spec/spec_helper.rb
         | 
| 88 | 
            -
            has_rdoc: 
         |