Skip to content

Commit

Permalink
New partial DSL
Browse files Browse the repository at this point in the history
This renders requested partial for a corresponding controller
with record supplied as an object,
i.e. local variable named after partial without underscore prefix.
  • Loading branch information
mlt committed Nov 28, 2019
1 parent 2b08088 commit c418c46
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/tabulatr/data/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ def column(name, opts = {}, &block)
@table_columns << table_column
end

def partial(name, opts = {}, &block)
@table_columns ||= []
sql_options = determine_sql(opts, main_class.quoted_table_name, name)
opts = {
sort_sql: sql_options[:sort_sql],
filter: false,
sortable: false,
filter_sql: sql_options[:filter_sql]}.merge(opts)
table_column = Tabulatr::Renderer::Column.from(
name: name,
klass: @base,
proxy: self,
col_options: Tabulatr::ParamsBuilder.new(opts),
table_name: main_class.table_name.to_sym,
output: block_given? ? block : ->(record){ self.controller.render_to_string partial: name.to_s, formats: [:html], object: record })
@table_columns << table_column
end

def association(assoc, name, opts = {}, &block)
@table_columns ||= []
unless assoc.is_a?(Array)
Expand Down

0 comments on commit c418c46

Please sign in to comment.