Module: RailsDb::ApplicationHelper
- Defined in:
- app/helpers/rails_db/application_helper.rb
Instance Method Summary collapse
- #db_hint_options ⇒ Object
- #fa_icon(icon_name) ⇒ Object
-
#guess_name(sections) ⇒ Object
in case engine was added in namespace.
- #link_to_add_fields(name, f, type) ⇒ Object
- #main_content_classes ⇒ Object
- #params_to_hash(p) ⇒ Object
- #rails_db ⇒ Object
- #rails_db_tables ⇒ Object
- #show_sidebar? ⇒ Boolean
- #sidebar_classes ⇒ Object
- #title(str) ⇒ Object
Instance Method Details
#db_hint_options ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/helpers/rails_db/application_helper.rb', line 66 def result = {} RailsDb::Database.accessible_tables.each do |table_name| result[table_name] = RailsDb::Table.new(table_name).columns.inject([]) {|res, e| res << e.name; res } end result end |
#fa_icon(icon_name) ⇒ Object
62 63 64 |
# File 'app/helpers/rails_db/application_helper.rb', line 62 def fa_icon(icon_name) %{<i class="fa fa-#{icon_name}"></i>}.html_safe end |
#guess_name(sections) ⇒ Object
in case engine was added in namespace
11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/rails_db/application_helper.rb', line 11 def guess_name(sections) if sections.size > 1 sections[-1] = 'rails_db' variable = sections.join("_") result = eval(variable) end rescue NameError sections.delete_at(-2) guess_name(sections) end |
#link_to_add_fields(name, f, type) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/helpers/rails_db/application_helper.rb', line 26 def link_to_add_fields(name, f, type) new_object = f.object.send "build_#{type}" id = "new_#{type}" fields = f.send("#{type}_fields", new_object, child_index: id) do |builder| render(type.to_s + "_fields", f: builder) end link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")}) end |
#main_content_classes ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/helpers/rails_db/application_helper.rb', line 43 def main_content_classes if 'large-9 push-3 columns collapsed' else 'large-12 push-0 columns expanded' end end |
#params_to_hash(p) ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/helpers/rails_db/application_helper.rb', line 74 def params_to_hash(p) if p.respond_to?(:to_unsafe_h) p.to_unsafe_h else p end end |
#rails_db ⇒ Object
4 5 6 7 8 |
# File 'app/helpers/rails_db/application_helper.rb', line 4 def rails_db super rescue NameError guess_name(request.path.split('/').reject(&:blank?)) end |
#rails_db_tables ⇒ Object
22 23 24 |
# File 'app/helpers/rails_db/application_helper.rb', line 22 def rails_db_tables RailsDb::Database.accessible_tables end |
#show_sidebar? ⇒ Boolean
51 52 53 54 |
# File 'app/helpers/rails_db/application_helper.rb', line 51 def return true if controller_name == 'dashboard' && action_name == 'index' ['sidebar_hidden'] != 'true' end |
#sidebar_classes ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/helpers/rails_db/application_helper.rb', line 35 def if 'large-3 large-pull-9 columns' else 'large-3 large-pull-9 columns hide' end end |
#title(str) ⇒ Object
56 57 58 59 60 |
# File 'app/helpers/rails_db/application_helper.rb', line 56 def title(str) content_for :title do raw("#{str}"[0].upcase + "#{str}"[1..-1]) end end |