Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
leikind committed Aug 28, 2015
1 parent b9086ea commit 20acd35
Show file tree
Hide file tree
Showing 27 changed files with 149 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .inch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files:
excluded:
- lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb
5 changes: 0 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ Style/SpaceBeforeComma:
Style/SpaceInsideParens:
Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/TrailingBlankLines:
Enabled: true

# Cop supports --auto-correct.
Style/DeprecatedHashMethods:
Enabled: true
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ task :coverage do
Rake::Task['spec'].execute
end

# Experimenting with documentation system we will keep both Yardoc and Rdoc for some time, plus Inch

require 'yard'
require 'yard/rake/yardoc_task'
Expand All @@ -55,4 +56,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end

task default: [:rubocop, :spec, :rdoc]
task default: [:rubocop, :spec, :yardoc]
1 change: 1 addition & 0 deletions lib/wice/active_record_column_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Wice
# to be mixed in into ActiveRecord::ConnectionAdapters::Column
module WiceGridExtentionToActiveRecordColumn #:nodoc:
# reference to the ActiveRecord model class
attr_accessor :model
end

Expand Down
21 changes: 19 additions & 2 deletions lib/wice/columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,25 @@ class ViewColumn #:nodoc:

attr_accessor(*FIELDS)

attr_accessor :cell_rendering_block, :grid, :table_name, :main_table, :model, :custom_filter
# a Proc object which would return contents of one cell
attr_accessor :cell_rendering_block

# reference to the WiceGrid instance
attr_accessor :grid

# name of the table
attr_accessor :table_name

# name of the main table (first argument to initialize_grid)
attr_accessor :main_table

# attr_accessor :model

# specification for a custom filter: an array of option label + option value pairs for the select, or a Proc object which returns this array.
# Or nil if it is not a custom filter
attr_accessor :custom_filter

# A boolean flag: whether a column has a text input or not
attr_reader :contains_a_text_input

def initialize(block, options, grid_obj, tname, mtable, cfilter, view) #:nodoc:
Expand All @@ -121,7 +138,7 @@ def initialize(block, options, grid_obj, tname, mtable, cfilter, view) #:nodoc:
end
end

def add_css_class(klass_value)
def add_css_class(klass_value) #:nodoc:
self.html ||= {}
if html[:class].nil?
html[:class] = klass_value
Expand Down
6 changes: 5 additions & 1 deletion lib/wice/columns/column_boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ module Columns #:nodoc:
class ViewColumnBoolean < ViewColumnCustomDropdown #:nodoc:
include ActionView::Helpers::FormOptionsHelper

attr_accessor :boolean_filter_true_label, :boolean_filter_false_label
# Text for the true value
attr_accessor :boolean_filter_true_label

# Text for the false value
attr_accessor :boolean_filter_false_label

def render_filter_internal(params) #:nodoc:
@custom_filter = {
Expand Down
27 changes: 16 additions & 11 deletions lib/wice/columns/column_custom_dropdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ module Columns #:nodoc:
class ViewColumnCustomDropdown < ViewColumn #:nodoc:
include ActionView::Helpers::FormOptionsHelper

# text in the filter dropdown for an empty <option><option>
attr_accessor :filter_all_label

# contains an array of option label + option value pairs for the select, or a Proc object which returns this array
attr_accessor :custom_filter

def render_filter_internal(params) #:nodoc:
Expand All @@ -30,18 +33,20 @@ def render_filter_internal(params) #:nodoc:
expand_icon_style, collapse_icon_style = nil, 'display: none'
expand_icon_style, collapse_icon_style = collapse_icon_style, expand_icon_style if select_options[:multiple]

select_toggle = content_tag(:span,
content_tag(:i, '', class: 'fa fa-plus'),
title: NlMessage['expand'],
class: 'expand-multi-select-icon clickable',
style: expand_icon_style
select_toggle = content_tag(
:span,
content_tag(:i, '', class: 'fa fa-plus'),
title: NlMessage['expand'],
class: 'expand-multi-select-icon clickable',
style: expand_icon_style
) +
content_tag(:span,
content_tag(:i, '', class: 'fa fa-minus'),
title: NlMessage['collapse'],
class: 'collapse-multi-select-icon clickable',
style: collapse_icon_style
)
content_tag(
:span,
content_tag(:i, '', class: 'fa fa-minus'),
title: NlMessage['collapse'],
class: 'collapse-multi-select-icon clickable',
style: collapse_icon_style
)
else
select_options[:multiple] = false
select_toggle = ''
Expand Down
2 changes: 1 addition & 1 deletion lib/wice/columns/column_integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def has_auto_reloading_input? #:nodoc:
end

class ConditionsGeneratorColumnInteger < ConditionsGeneratorColumn #:nodoc:
def get_op_and_value(val)
def get_op_and_value(val) #:nodoc:
num = nil
op = nil

Expand Down
2 changes: 1 addition & 1 deletion lib/wice/columns/column_rails_date_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ViewColumnRailsDateHelper < ViewColumn #:nodoc:
include Wice::Columns::CommonDateDatetimeMixin
include Wice::Columns::CommonStandardDateDatetimeMixin

def chunk_names
def chunk_names #:nodoc:
%w(year month day)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/wice/columns/column_rails_datetime_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ViewColumnRailsDatetimeHelper < ViewColumn #:nodoc:
include Wice::Columns::CommonDateDatetimeMixin
include Wice::Columns::CommonStandardDateDatetimeMixin

def chunk_names
def chunk_names #:nodoc:
%w(year month day hour minute)
end

Expand Down
7 changes: 6 additions & 1 deletion lib/wice/columns/column_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
module Wice
module Columns #:nodoc:
class ViewColumnString < ViewColumn #:nodoc:
attr_accessor :negation, :auto_reloading_input_with_negation_checkbox

# whether the filter contains a negation checkbox
attr_accessor :negation

# whether the filter contains a negation checkbox and autoreloading is necessary
attr_accessor :auto_reloading_input_with_negation_checkbox

def render_filter_internal(params) #:nodoc:
@contains_a_text_input = true
Expand Down
9 changes: 9 additions & 0 deletions lib/wice/grid_output_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
# encoding: utf-8
module Wice
class GridOutputBuffer < String #:nodoc:

# defines behavior for rendering nonexistent filters.
# If return_empty_strings_for_nonexistent_filters is true, a call to render a non existent filter will raise an exception
# If return_empty_strings_for_nonexistent_filters is false (CSV mode), no exception will be raised.
attr_accessor :return_empty_strings_for_nonexistent_filters

# initializes a grid output buffer
def initialize(*attrs)
super(*attrs)
@filters = HashWithIndifferentAccess.new
end

# returns HTML code the grid
def to_s
super.html_safe
end

# stores HTML code for a detached filter
def add_filter(detach_with_id, filter_code)
fail WiceGridException.new("Detached ID #{detach_with_id} is already used!") if @filters.key? detach_with_id
@filters[detach_with_id] = filter_code
end

# returns HTML code for a detached filter
def filter_for(detach_with_id)
unless @filters.key? detach_with_id
if @return_empty_strings_for_nonexistent_filters
Expand All @@ -35,6 +43,7 @@ def filter_for(detach_with_id)
res
end

# returns HTML code for a detached filter
alias_method :[], :filter_for
end
end
40 changes: 27 additions & 13 deletions lib/wice/grid_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,40 @@ class GridRenderer
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::JavaScriptHelper

attr_reader :page_parameter_name
# a Proc object for the after_row block
attr_reader :after_row_handler

# a Proc object for the before_row block
attr_reader :before_row_handler

# a Proc object for the replace_row block
attr_reader :replace_row_handler

# Configuration or a Proc object for the blank_slate block
attr_reader :blank_slate_handler

# a Proc object which returns contents of the last row
attr_reader :last_row_handler

# reference to the WiceGrid instance
attr_reader :grid

# Contents of <caption></caption>
attr_reader :kaption

@@order_parameter_name = 'order'
@@order_direction_parameter_name = 'order_direction'
@@page_parameter_name = 'page'
# HTTP parameter for the order field
ORDER_PARAMETER_NAME = 'order'

# HTTP parameter for the order direction (asc/desc)
ORDER_DIRECTION_PARAMETER_NAME = 'order_direction'

def initialize(grid, view) #:nodoc:
@grid = grid
@grid.renderer = self
@columns = []
@columns_table = {}
@grid = grid
@grid.renderer = self
@columns = []
@columns_table = {}
@action_column_present = false
@view = view
@view = view
end

def config #:nodoc:
Expand Down Expand Up @@ -119,8 +133,8 @@ def pagination_panel(number_of_columns, hide_csv_button) #:nodoc:
end
end

# Takes one argument and adds the <caption></caption> tag to the table with the argument value as
# the contents of <caption>.
# Takes one argument and adds the <caption></caption> tag to the table with the
# argument value as the contents of <caption>.
def caption(kaption)
@kaption = kaption
end
Expand Down Expand Up @@ -561,8 +575,8 @@ def column_link(column, direction, params, extra_parameters = {}) #:nodoc:
end

query_params = { @grid.name => {
@@order_parameter_name => column_attribute_name,
@@order_direction_parameter_name => direction
ORDER_PARAMETER_NAME => column_attribute_name,
ORDER_DIRECTION_PARAMETER_NAME => direction
} }

cleaned_params = Wice::WgHash.deep_clone params
Expand Down
5 changes: 4 additions & 1 deletion lib/wice/helpers/bs_calendar_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# encoding: utf-8
module Wice #:nodoc:
module BsCalendarHelpers #:nodoc:

# A struct containing all data for rendering a calendar
class CalendarData #:nodoc:

# :nodoc:
attr_accessor :name,
:date_string,
:dom_id,
Expand All @@ -11,7 +14,7 @@ class CalendarData #:nodoc:
:fire_event,
:close_calendar_event_name,
:the_other_datepicker_id_to,
:the_other_datepicker_id_from #:nodoc:
:the_other_datepicker_id_from
end

def date_calendar_bs(calendar_data) #:nodoc:
Expand Down
28 changes: 17 additions & 11 deletions lib/wice/helpers/js_calendar_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# encoding: utf-8
module Wice #:nodoc:
module JsCalendarHelpers #:nodoc:

# A struct containing all data for rendering a calendar
class CalendarData

# :nodoc:
attr_accessor :name,
:date_string,
:dom_id,
Expand Down Expand Up @@ -44,18 +48,20 @@ def date_calendar_jquery(calendar_data) #:nodoc:

date_picker = hidden_field_tag(calendar_data.name, calendar_data.date_string, hidden_field_tag_options) + ' ' +

link_to(calendar_data.date_string,
'#',
:id => calendar_data.date_span_id,
:class => 'date-label',
:title => ::Wice::NlMessage['date_string_tooltip'],
'data-dom-id' => calendar_data.dom_id
)
link_to(
calendar_data.date_string,
'#',
:id => calendar_data.date_span_id,
:class => 'date-label',
:title => ::Wice::NlMessage['date_string_tooltip'],
'data-dom-id' => calendar_data.dom_id
)

content_tag(:span,
date_picker,
id: calendar_data.datepicker_placeholder_id,
class: 'jq-datepicker-container'
content_tag(
:span,
date_picker,
id: calendar_data.datepicker_placeholder_id,
class: 'jq-datepicker-container'
)
end

Expand Down
3 changes: 3 additions & 0 deletions lib/wice/helpers/wice_grid_misc_view_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# encoding: utf-8
module Wice

# Various grid related helpers
module GridViewHelper
# This method dumps all HTTP parameters related to filtering and ordering of a certain grid as hidden form fields.
# This might be required if you want to keep the state of a grid while reloading the page using other forms.
Expand Down Expand Up @@ -39,6 +41,7 @@ def filter_and_order_state_as_hash(grid)
}
end

# display the state of the grid
def dump_state(grid) #:nodoc:
debug(grid.get_state_as_parameter_value_pairs)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/wice/kaminari_monkey_patching.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: utf-8
# It is here only until this pull request is pulled: https://github.com/amatsuda/kaminari/pull/267

# Ugly monkey-patching Kaminari (https://github.com/amatsuda/kaminari/pull/267)
module Kaminari #:nodoc:
module Helpers #:nodoc:
class Tag #:nodoc:
Expand Down
Loading

0 comments on commit 20acd35

Please sign in to comment.