Sha256: 21903e96f56f001767ded04a7efb66bc17733b23e4b768713402800e7a1e3c3b

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require 'ykxutils/erubyx'

module Ykxutils
  module Gridlist
    TAMPLETES = { :GRID_DEF =>
      { :TEMPLATE => %!
    .g-<%= row %>-<%= colum %> {
      grid-row-start: <%= row %>;
      grid-row-end: ,<%= row + 1 %>;
      grid-column-start: <%= colum %>;
      grid-column-end: <%= colum + 1 %>;
    }
    !, :OBJ => nil } }

    module_function

    def make_one_grid(hash, row, colum)
      unless hash[:OBJ]
        hash[:OBJ] = Tilt::ErubiTemplate.new { hash[:TEMPLATE] }
      end
      hash[:OBJ].render(Object.new, { row: row, colum: colum })
    end

    def make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
      (min_row..max_row).map { |row|
        (min_colum..max_colum).map { |colum|
          # puts "#{row} #{colum}"
          value_hash = { row: row, colum: colum }
          # make_one_grid(template_hash, value_hash)
          # p template_hash
          # p value_hash
          Ykxutils::Erubyx::erubi_render(template_hash, scope, value_hash)
        }
      }
    end

    def make_grid_list(min_row, max_row, min_colum, max_colum)
      template_hash = TAMPLETES[:GRID_DEF]
      scope = nil
      make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
    end

    def make_grid_list_x(min_row, max_row, min_colum, max_colum)
      template_hash = TAMPLETES[:GRID_DEF]
      scope = nil
      make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ykxutils-0.1.8 lib/ykxutils/gridlist.rb