barkest_core 1.5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +254 -0
- data/MIT-LICENSE +20 -0
- data/README.md +364 -0
- data/Rakefile +37 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Bold.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-BoldItalic.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Italic.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Regular.ttf +0 -0
- data/app/assets/images/barkest_core/.keep +0 -0
- data/app/assets/images/barkest_core/barcode-B.svg +181 -0
- data/app/assets/javascripts/barkest_core/.keep +0 -0
- data/app/assets/javascripts/barkest_core/application.js +22 -0
- data/app/assets/javascripts/barkest_core/bootstrap-datepicker.js +1800 -0
- data/app/assets/javascripts/barkest_core/field_init.js +7 -0
- data/app/assets/javascripts/barkest_core/jquery.doubleScroll.js +112 -0
- data/app/assets/javascripts/barkest_core/masked_edit.js +25 -0
- data/app/assets/javascripts/barkest_core/system_status.js.erb +201 -0
- data/app/assets/stylesheets/barkest_core/.keep +0 -0
- data/app/assets/stylesheets/barkest_core/application.css +17 -0
- data/app/assets/stylesheets/barkest_core/custom.css.scss +264 -0
- data/app/assets/stylesheets/barkest_core/datepicker3.css +790 -0
- data/app/controllers/.keep +0 -0
- data/app/controllers/access_groups_controller.rb +74 -0
- data/app/controllers/account_activations_controller.rb +29 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/barkest_core/application_controller_base.rb +113 -0
- data/app/controllers/barkest_core/engine_controller_base.rb +15 -0
- data/app/controllers/barkest_core/testsub_controller.rb +21 -0
- data/app/controllers/contact_controller.rb +32 -0
- data/app/controllers/log_view_controller.rb +31 -0
- data/app/controllers/password_resets_controller.rb +126 -0
- data/app/controllers/sessions_controller.rb +64 -0
- data/app/controllers/status_controller.rb +150 -0
- data/app/controllers/system_config_controller.rb +238 -0
- data/app/controllers/system_update_controller.rb +164 -0
- data/app/controllers/test_access_controller.rb +44 -0
- data/app/controllers/test_report_controller.rb +75 -0
- data/app/controllers/users_controller.rb +218 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/barkest_core/application_helper.rb +134 -0
- data/app/helpers/barkest_core/form_helper.rb +469 -0
- data/app/helpers/barkest_core/html_helper.rb +70 -0
- data/app/helpers/barkest_core/misc_helper.rb +68 -0
- data/app/helpers/barkest_core/pdf_helper.rb +180 -0
- data/app/helpers/barkest_core/recaptcha_helper.rb +115 -0
- data/app/helpers/barkest_core/sessions_helper.rb +94 -0
- data/app/helpers/barkest_core/status_helper.rb +118 -0
- data/app/helpers/barkest_core/users_helper.rb +32 -0
- data/app/mailers/.keep +0 -0
- data/app/mailers/application_mailer.rb +5 -0
- data/app/mailers/barkest_core/application_mailer_base.rb +30 -0
- data/app/mailers/barkest_core/contact_form.rb +20 -0
- data/app/mailers/barkest_core/user_mailer.rb +44 -0
- data/app/models/.keep +0 -0
- data/app/models/access_group.rb +121 -0
- data/app/models/access_group_group_member.rb +13 -0
- data/app/models/access_group_user_member.rb +11 -0
- data/app/models/barkest_core/auth_config.rb +95 -0
- data/app/models/barkest_core/authorize_failure.rb +7 -0
- data/app/models/barkest_core/contact_message.rb +37 -0
- data/app/models/barkest_core/database_config.rb +223 -0
- data/app/models/barkest_core/db_table.rb +21 -0
- data/app/models/barkest_core/email_config.rb +132 -0
- data/app/models/barkest_core/global_status.rb +267 -0
- data/app/models/barkest_core/log_entry.rb +101 -0
- data/app/models/barkest_core/log_view_options.rb +51 -0
- data/app/models/barkest_core/ms_sql_db_definition.rb +441 -0
- data/app/models/barkest_core/ms_sql_definition.rb +221 -0
- data/app/models/barkest_core/ms_sql_function.rb +423 -0
- data/app/models/barkest_core/not_logged_in.rb +7 -0
- data/app/models/barkest_core/pdf_table_builder.rb +407 -0
- data/app/models/barkest_core/self_update_config.rb +37 -0
- data/app/models/barkest_core/user_alert.rb +29 -0
- data/app/models/barkest_core/user_alert_generators.rb +58 -0
- data/app/models/barkest_core/user_manager.rb +404 -0
- data/app/models/barkest_core/work_path.rb +74 -0
- data/app/models/disable_user.rb +18 -0
- data/app/models/ldap_access_group.rb +15 -0
- data/app/models/system_config.rb +99 -0
- data/app/models/user.rb +405 -0
- data/app/models/user_login_history.rb +11 -0
- data/app/views/.keep +0 -0
- data/app/views/access_groups/_form.html.erb +19 -0
- data/app/views/access_groups/edit.html.erb +2 -0
- data/app/views/access_groups/index.html.erb +32 -0
- data/app/views/access_groups/new.html.erb +2 -0
- data/app/views/access_groups/show.html.erb +4 -0
- data/app/views/barkest_core/contact_form/contact.html.erb +16 -0
- data/app/views/barkest_core/contact_form/contact.text.erb +13 -0
- data/app/views/barkest_core/testsub/_links.html.erb +5 -0
- data/app/views/barkest_core/testsub/page1.html.erb +3 -0
- data/app/views/barkest_core/testsub/page2.html.erb +2 -0
- data/app/views/barkest_core/testsub/page3.html.erb +2 -0
- data/app/views/barkest_core/user_mailer/account_activation.html.erb +7 -0
- data/app/views/barkest_core/user_mailer/account_activation.text.erb +6 -0
- data/app/views/barkest_core/user_mailer/invalid_password_reset.html.erb +3 -0
- data/app/views/barkest_core/user_mailer/invalid_password_reset.text.erb +5 -0
- data/app/views/barkest_core/user_mailer/password_reset.html.erb +8 -0
- data/app/views/barkest_core/user_mailer/password_reset.text.erb +7 -0
- data/app/views/contact/index.html.erb +24 -0
- data/app/views/layouts/_footer_copyright.html.erb +1 -0
- data/app/views/layouts/_menu_admin.html.erb +5 -0
- data/app/views/layouts/_menu_anon.html.erb +0 -0
- data/app/views/layouts/_menu_auth.html.erb +3 -0
- data/app/views/layouts/_menu_footer.html.erb +1 -0
- data/app/views/layouts/_nav_logo.html.erb +1 -0
- data/app/views/layouts/application.html.erb +2 -0
- data/app/views/layouts/barkest_core/_application.html.erb +24 -0
- data/app/views/layouts/barkest_core/_footer.html.erb +18 -0
- data/app/views/layouts/barkest_core/_header.html.erb +38 -0
- data/app/views/layouts/barkest_core/_html_mailer.html.erb +11 -0
- data/app/views/layouts/barkest_core/_menu_account.html.erb +14 -0
- data/app/views/layouts/barkest_core/_menu_sample.html.erb +1 -0
- data/app/views/layouts/barkest_core/_messages.html.erb +4 -0
- data/app/views/layouts/barkest_core/_shim.html.erb +4 -0
- data/app/views/layouts/barkest_core/_subheader.html.erb +1 -0
- data/app/views/layouts/barkest_core/_text_mailer.text.erb +4 -0
- data/app/views/layouts/mailer.html.erb +1 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app/views/log_view/index.html.erb +100 -0
- data/app/views/password_resets/edit.html.erb +20 -0
- data/app/views/password_resets/new.html.erb +14 -0
- data/app/views/sessions/new.html.erb +27 -0
- data/app/views/shared/_error_messages.html.erb +29 -0
- data/app/views/shared/_generic_user_alert.html.erb +4 -0
- data/app/views/status/current.html.erb +34 -0
- data/app/views/status/test.html.erb +50 -0
- data/app/views/system_config/index.html.erb +25 -0
- data/app/views/system_config/show_auth.html.erb +28 -0
- data/app/views/system_config/show_database.html.erb +36 -0
- data/app/views/system_config/show_email.html.erb +21 -0
- data/app/views/system_config/show_self_update.html.erb +13 -0
- data/app/views/system_update/index.html.erb +31 -0
- data/app/views/system_update/new.html.erb +2 -0
- data/app/views/test_access/allow_anon.html.erb +2 -0
- data/app/views/test_access/require_admin.html.erb +2 -0
- data/app/views/test_access/require_group_x.html.erb +2 -0
- data/app/views/test_access/require_user.html.erb +2 -0
- data/app/views/test_report/index.csv.csvrb +23 -0
- data/app/views/test_report/index.html.erb +6 -0
- data/app/views/test_report/index.pdf.prawn +50 -0
- data/app/views/test_report/index.xlsx.axlsx +28 -0
- data/app/views/users/_user.html.erb +57 -0
- data/app/views/users/_user_details.html.erb +15 -0
- data/app/views/users/_user_details_for_list.html.erb +1 -0
- data/app/views/users/_user_form.html.erb +13 -0
- data/app/views/users/disable_confirm.html.erb +19 -0
- data/app/views/users/edit.html.erb +15 -0
- data/app/views/users/index.html.erb +9 -0
- data/app/views/users/new.html.erb +10 -0
- data/app/views/users/show.html.erb +46 -0
- data/bin/rails +12 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20160617172539_create_access_groups.rb +10 -0
- data/db/migrate/20160617172725_create_users.rb +26 -0
- data/db/migrate/20160617172833_create_user_login_histories.rb +12 -0
- data/db/migrate/20160622151720_create_access_group_user_members.rb +9 -0
- data/db/migrate/20160622151925_create_access_group_group_members.rb +9 -0
- data/db/migrate/20160701005706_create_ldap_access_groups.rb +11 -0
- data/db/migrate/20161108155029_create_system_configs.rb +11 -0
- data/db/seeds/barkest_core_01_create_users.rb +42 -0
- data/db/seeds.rb +53 -0
- data/lib/barkest_core/concerns/association_with_defaults.rb +55 -0
- data/lib/barkest_core/concerns/boolean_parser.rb +88 -0
- data/lib/barkest_core/concerns/date_parser.rb +181 -0
- data/lib/barkest_core/concerns/email_tester.rb +55 -0
- data/lib/barkest_core/concerns/encrypted_fields.rb +156 -0
- data/lib/barkest_core/concerns/named_model.rb +73 -0
- data/lib/barkest_core/concerns/number_parser.rb +145 -0
- data/lib/barkest_core/concerns/utc_conversion.rb +60 -0
- data/lib/barkest_core/engine.rb +105 -0
- data/lib/barkest_core/extensions/active_record_extensions.rb +120 -0
- data/lib/barkest_core/extensions/application_configuration_extensions.rb +38 -0
- data/lib/barkest_core/extensions/application_extensions.rb +50 -0
- data/lib/barkest_core/extensions/axlsx_extenstions.rb +157 -0
- data/lib/barkest_core/extensions/fixture_set_extensions.rb +107 -0
- data/lib/barkest_core/extensions/generator_extensions.rb +271 -0
- data/lib/barkest_core/extensions/main_app_extensions.rb +35 -0
- data/lib/barkest_core/extensions/prawn_document_extensions.rb +367 -0
- data/lib/barkest_core/extensions/prawn_table_extensions.rb +131 -0
- data/lib/barkest_core/extensions/router_extensions.rb +106 -0
- data/lib/barkest_core/extensions/simple_formatter_extensions.rb +66 -0
- data/lib/barkest_core/extensions/test_case_extensions.rb +348 -0
- data/lib/barkest_core/extensions/time_extensions.rb +164 -0
- data/lib/barkest_core/handlers/csv_handler.rb +30 -0
- data/lib/barkest_core/version.rb +3 -0
- data/lib/barkest_core.rb +324 -0
- data/lib/generators/barkest/install_generator.rb +102 -0
- data/lib/generators/barkest_core/actions/01_patch_application_controller.rb +55 -0
- data/lib/generators/barkest_core/actions/02_patch_application_mailer.rb +56 -0
- data/lib/generators/barkest_core/actions/03_patch_assets.rb +62 -0
- data/lib/generators/barkest_core/actions/04_patch_layouts.rb +36 -0
- data/lib/generators/barkest_core/actions/05_patch_routes.rb +93 -0
- data/lib/generators/barkest_core/actions/06_patch_seeds.rb +60 -0
- data/lib/generators/barkest_core/actions/07_copy_migrations.rb +51 -0
- data/lib/generators/barkest_core/actions/08_configure_database.rb +52 -0
- data/lib/generators/barkest_core/actions/09_configure_secrets.rb +29 -0
- data/lib/generators/barkest_core/actions/99_patch_gitignore.rb +57 -0
- data/lib/generators/barkest_core/install_generator.rb +17 -0
- data/test/barkest_core_test.rb +83 -0
- data/test/controllers/access_groups_controller_test.rb +53 -0
- data/test/controllers/contact_controller_test.rb +10 -0
- data/test/controllers/sessions_controller_test.rb +10 -0
- data/test/controllers/users_controller_test.rb +10 -0
- data/test/dummy/.gitignore +10 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +14 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/mailers/application_mailer.rb +3 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/app/views/system_config/show_fake.html.erb +3 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +27 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +47 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/db_updater_ext.rb +33 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/sys_config_ext.rb +12 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/schema.rb +95 -0
- data/test/dummy/db/seeds/barkest_core_01_create_users.rb +42 -0
- data/test/dummy/db/seeds.rb +51 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/sql/my_test_view.sql +3 -0
- data/test/fixtures/access_groups.yml +21 -0
- data/test/fixtures/users.yml +71 -0
- data/test/helpers/barkest_core/sessions_helper_test.rb +22 -0
- data/test/integration/access_group_mgmt_test.rb +33 -0
- data/test/integration/access_test.rb +24 -0
- data/test/integration/account_activations_access_test.rb +12 -0
- data/test/integration/contact_test.rb +98 -0
- data/test/integration/extra_partial_test.rb +41 -0
- data/test/integration/log_view_access_test.rb +12 -0
- data/test/integration/password_resets_test.rb +101 -0
- data/test/integration/reports_test.rb +53 -0
- data/test/integration/status_access_test.rb +27 -0
- data/test/integration/system_config_access_test.rb +24 -0
- data/test/integration/system_update_access_test.rb +19 -0
- data/test/integration/users_access_test.rb +34 -0
- data/test/integration/users_edit_test.rb +178 -0
- data/test/integration/users_index_test.rb +62 -0
- data/test/integration/users_login_test.rb +67 -0
- data/test/integration/users_signup_test.rb +54 -0
- data/test/mailers/.keep +0 -0
- data/test/mailers/barkest_core/contact_form_test.rb +28 -0
- data/test/mailers/barkest_core/user_mailer_test.rb +43 -0
- data/test/mailers/previews/barkest_core/contact_form_preview.rb +17 -0
- data/test/mailers/previews/barkest_core/user_mailer_preview.rb +26 -0
- data/test/models/access_group_group_member_test.rb +28 -0
- data/test/models/access_group_test.rb +114 -0
- data/test/models/access_group_user_member_test.rb +28 -0
- data/test/models/barkest_core/auth_config_test.rb +57 -0
- data/test/models/barkest_core/bool_parser_test.rb +28 -0
- data/test/models/barkest_core/contact_message_test.rb +61 -0
- data/test/models/barkest_core/database_config_test.rb +33 -0
- data/test/models/barkest_core/date_parser_test.rb +110 -0
- data/test/models/barkest_core/email_config_test.rb +57 -0
- data/test/models/barkest_core/global_status_test.rb +50 -0
- data/test/models/barkest_core/ms_sql_db_updater_test.rb +115 -0
- data/test/models/barkest_core/ms_sql_definition_test.rb +102 -0
- data/test/models/barkest_core/ms_sql_function_test.rb +131 -0
- data/test/models/barkest_core/number_parser_test.rb +29 -0
- data/test/models/barkest_core/self_update_config_test.rb +29 -0
- data/test/models/barkest_core/user_alert_test.rb +19 -0
- data/test/models/barkest_core/user_manager_test.rb +34 -0
- data/test/models/barkest_core/work_path_test.rb +26 -0
- data/test/models/disable_user_test.rb +27 -0
- data/test/models/generic_time_test.rb +66 -0
- data/test/models/ldap_access_group_test.rb +31 -0
- data/test/models/pdf_table_builder_test.rb +6 -0
- data/test/models/system_config_test.rb +78 -0
- data/test/models/user_login_history_test.rb +37 -0
- data/test/models/user_test.rb +130 -0
- data/test/test_helper.rb +63 -0
- metadata +798 -0
@@ -0,0 +1,407 @@
|
|
1
|
+
module BarkestCore
|
2
|
+
|
3
|
+
##
|
4
|
+
# A table builder to ease creation of tables in PDF documents.
|
5
|
+
#
|
6
|
+
class PdfTableBuilder
|
7
|
+
|
8
|
+
##
|
9
|
+
# Creates a new table builder in the provided +document+.
|
10
|
+
#
|
11
|
+
# The options can specify both table options and :cell_style options.
|
12
|
+
# The :cell_style option should be a hash of styles for the cells in your table.
|
13
|
+
#
|
14
|
+
def initialize(document, options = {}, &block)
|
15
|
+
options ||= {}
|
16
|
+
|
17
|
+
@doc = document
|
18
|
+
|
19
|
+
@data = []
|
20
|
+
@col_offset = 0
|
21
|
+
@row_offset = 0
|
22
|
+
@col_start = 0
|
23
|
+
@in_row = false
|
24
|
+
|
25
|
+
@base_cell_options = { borders: [] }.merge(options[:cell_style] || { })
|
26
|
+
@options = options.except(:cell_style)
|
27
|
+
|
28
|
+
yield self if block_given?
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Gets the cell options provided during the TableBuilder creation.
|
33
|
+
def base_cell_options
|
34
|
+
@base_cell_options
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Gets the table options provided during the TableBuilder creation.
|
39
|
+
def table_options
|
40
|
+
@options
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Generates the table array used by Prawn::Table.
|
45
|
+
def to_table
|
46
|
+
@doc.make_table(data, table_options)
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Gets the current position in the table.
|
51
|
+
def position
|
52
|
+
[ @row_offset, @col_offset ]
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Gets the current row in the table.
|
57
|
+
def current_row
|
58
|
+
@row_offset
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Gets the current column in the table.
|
63
|
+
def current_column
|
64
|
+
@col_offset
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# Gets the last row in the table.
|
69
|
+
def last_row
|
70
|
+
@data.length - 1
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Gets the last column in the table.
|
75
|
+
def last_column
|
76
|
+
max = 0
|
77
|
+
@data.each do |row|
|
78
|
+
max = row.length if max < row.length
|
79
|
+
end
|
80
|
+
max - 1
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Builds data starting at the specified column.
|
85
|
+
#
|
86
|
+
# The +start_column+ is the first column you want to be building.
|
87
|
+
# When you start a new row inside of a build_column block, the new row
|
88
|
+
# starts at this same column.
|
89
|
+
def build_column(start_column = nil)
|
90
|
+
if block_given?
|
91
|
+
raise StandardError.new('build_column block called within row block') if @in_row
|
92
|
+
raise StandardError.new('build_column called without valid argument') unless start_column.is_a?(Numeric)
|
93
|
+
|
94
|
+
backup_col_start = @col_start
|
95
|
+
backup_col_offset = @col_offset
|
96
|
+
backup_row_offset = @row_offset
|
97
|
+
@col_start = start_column.to_i
|
98
|
+
@col_offset = @col_start
|
99
|
+
@row_offset = 0
|
100
|
+
|
101
|
+
yield
|
102
|
+
|
103
|
+
@col_start = backup_col_start
|
104
|
+
@col_offset = backup_col_offset
|
105
|
+
@row_offset = backup_row_offset
|
106
|
+
end
|
107
|
+
@col_start
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Builds a row in the table.
|
112
|
+
#
|
113
|
+
# Valid options:
|
114
|
+
#
|
115
|
+
# row::
|
116
|
+
# Defines the row you want to start on. If not set, then it uses #current_row.
|
117
|
+
#
|
118
|
+
# Additional options are merged with the base cell options for this row.
|
119
|
+
#
|
120
|
+
# When it completes, the #current_row is set to 1 more than the row we started on.
|
121
|
+
#
|
122
|
+
def row(options = {}, &block)
|
123
|
+
raise StandardError.new('row called within row block') if @in_row
|
124
|
+
|
125
|
+
@in_row = true
|
126
|
+
@col_offset = @col_start
|
127
|
+
options = change_row(options || {})
|
128
|
+
|
129
|
+
@row_cell_options = @base_cell_options.merge(options)
|
130
|
+
|
131
|
+
fill_cells(@row_offset, @col_offset)
|
132
|
+
|
133
|
+
# skip placeholders when starting a new row.
|
134
|
+
if @data[@row_offset]
|
135
|
+
while @data[@row_offset][@col_offset] == :span_placeholder
|
136
|
+
@col_offset += 1
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
yield if block_given?
|
141
|
+
|
142
|
+
@in_row = false
|
143
|
+
@row_offset += 1
|
144
|
+
@row_cell_options = nil
|
145
|
+
end
|
146
|
+
|
147
|
+
##
|
148
|
+
# Builds a subtable within the current row.
|
149
|
+
#
|
150
|
+
# The +cell_options+ are passed to the current cell.
|
151
|
+
# The +options+ are passed to the new TableBuilder.
|
152
|
+
#
|
153
|
+
def subtable(cell_options = {}, options = {}, &block)
|
154
|
+
raise StandardError.new('subtable called outside of row block') unless @in_row
|
155
|
+
cell cell_options || {} do
|
156
|
+
PdfTableBuilder.new(@doc, options || {}, &block).to_table
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# Creates a bold cell.
|
162
|
+
#
|
163
|
+
# See #cell for valid options.
|
164
|
+
#
|
165
|
+
def bold_cell(options = {}, &block)
|
166
|
+
cell({ font_style: :bold }.merge(options || {}), &block)
|
167
|
+
end
|
168
|
+
|
169
|
+
##
|
170
|
+
# Creates an italicized cell.
|
171
|
+
#
|
172
|
+
# See #cell for valid options.
|
173
|
+
#
|
174
|
+
def italic_cell(options = {}, &block)
|
175
|
+
cell({ font_style: :italic }.merge(options || {}), &block)
|
176
|
+
end
|
177
|
+
|
178
|
+
##
|
179
|
+
# Creates a bold-italic cell.
|
180
|
+
#
|
181
|
+
# See #cell for valid options.
|
182
|
+
#
|
183
|
+
def bold_italic_cell(options = {}, &block)
|
184
|
+
cell({ font_style: :bold_italic }.merge(options || {}), &block)
|
185
|
+
end
|
186
|
+
|
187
|
+
##
|
188
|
+
# Creates an underlined cell.
|
189
|
+
#
|
190
|
+
# See #cell for valid options.
|
191
|
+
#
|
192
|
+
def underline_cell(options = {}, &block)
|
193
|
+
cell({ borders: [ :bottom ], border_width: 0.5 }.merge(options || {}), &block)
|
194
|
+
end
|
195
|
+
|
196
|
+
##
|
197
|
+
# Creates multiple cells.
|
198
|
+
#
|
199
|
+
# Individual cells can be given options by prefixing the keys with 'cell_#' where # is the cell number (starting at 1).
|
200
|
+
#
|
201
|
+
# See #cell for valid options.
|
202
|
+
#
|
203
|
+
def cells(options = {}, &block)
|
204
|
+
cell_regex = /^cell_([0-9]+)_/
|
205
|
+
|
206
|
+
options ||= { }
|
207
|
+
|
208
|
+
result = block_given? ? yield : (options[:values] || [''])
|
209
|
+
|
210
|
+
cell_options = result.map { {} }
|
211
|
+
common_options = {}
|
212
|
+
|
213
|
+
options.each do |k,v|
|
214
|
+
# if the option starts with 'cell_#_' then apply it accordingly.
|
215
|
+
if (m = cell_regex.match(k.to_s))
|
216
|
+
k = k.to_s[m[0].length..-1].to_sym
|
217
|
+
cell_options[m[1].to_i - 1][k] = v
|
218
|
+
|
219
|
+
# the 'column' option applies only to the first cell.
|
220
|
+
elsif k == :column
|
221
|
+
cell_options[0][k] = v
|
222
|
+
|
223
|
+
# everything else applies to all cells, unless overridden explicitly.
|
224
|
+
elsif k != :values
|
225
|
+
common_options[k] = v
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
cell_options.each_with_index do |opt,idx|
|
230
|
+
cell common_options.merge(opt).merge( { value: result[idx] } )
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
##
|
235
|
+
# Creates a pair of cells.
|
236
|
+
# The first cell is bold with the :key option and the second cell is normal with the :value option.
|
237
|
+
#
|
238
|
+
# Additional options can be specified as they are in #cells.
|
239
|
+
#
|
240
|
+
def key_value(options = {}, &block)
|
241
|
+
options ||= {}
|
242
|
+
|
243
|
+
if options[:key]
|
244
|
+
options[:values] ||= []
|
245
|
+
options[:values][0] = options[:key]
|
246
|
+
end
|
247
|
+
if options[:value]
|
248
|
+
options[:values] ||= []
|
249
|
+
options[:values][1] = options[:value]
|
250
|
+
end
|
251
|
+
|
252
|
+
options = {
|
253
|
+
cell_1_font_style: :bold
|
254
|
+
}.merge(options.except(:key, :value))
|
255
|
+
|
256
|
+
cells options, &block
|
257
|
+
end
|
258
|
+
|
259
|
+
##
|
260
|
+
# Generates a cell in the current row.
|
261
|
+
#
|
262
|
+
# Valid options:
|
263
|
+
#
|
264
|
+
# value::
|
265
|
+
# The value to put in the cell, unless a code block is provided, in which case the result of the code block is used.
|
266
|
+
#
|
267
|
+
# rowspan::
|
268
|
+
# The number of rows for this cell to cover.
|
269
|
+
#
|
270
|
+
# colspan::
|
271
|
+
# The number of columns for this cell to cover.
|
272
|
+
#
|
273
|
+
# Additional options are embedded and passed on to Prawn::Table, see {Prawn PDF Table Manual}[http://prawnpdf.org/prawn-table-manual.pdf] for more information.
|
274
|
+
#
|
275
|
+
def cell(options = {}, &block)
|
276
|
+
raise StandardError.new('cell called outside of row block') unless @in_row
|
277
|
+
|
278
|
+
options = @row_cell_options.merge(options || {})
|
279
|
+
|
280
|
+
options = change_col(options)
|
281
|
+
|
282
|
+
result = block_given? ? yield : (options[:value] || '')
|
283
|
+
|
284
|
+
options.except!(:value)
|
285
|
+
|
286
|
+
set_cell(result, nil, nil, options)
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
private
|
291
|
+
|
292
|
+
def data
|
293
|
+
fix_row_widths
|
294
|
+
# remove all placeholders.
|
295
|
+
ret = @data.map do |row|
|
296
|
+
row.delete_if { |item| item == :span_placeholder }
|
297
|
+
end
|
298
|
+
# remove all empty rows.
|
299
|
+
ret.delete_if { |row| row.empty? }
|
300
|
+
end
|
301
|
+
|
302
|
+
def change_row(options)
|
303
|
+
if options[:row] && options[:row] >= 0
|
304
|
+
@row_offset = options[:row]
|
305
|
+
end
|
306
|
+
options.except(:row)
|
307
|
+
end
|
308
|
+
|
309
|
+
def change_col(options)
|
310
|
+
if options[:column] && options[:column] >= 0
|
311
|
+
@col_offset = @col_start + options[:column]
|
312
|
+
end
|
313
|
+
options.except(:column)
|
314
|
+
end
|
315
|
+
|
316
|
+
def fill_cells(row, col)
|
317
|
+
return unless row >= 0 && col >= 0
|
318
|
+
|
319
|
+
if @data.length <= row
|
320
|
+
@data += [[ (@row_cell_options || @base_cell_options).merge({content: ''}) ]] * (row - @data.length + 1)
|
321
|
+
end
|
322
|
+
|
323
|
+
if @data[row].length <= col
|
324
|
+
@data[row] += [ (@row_cell_options || @base_cell_options).merge({content: ''}) ] * (col - @data[row].length + 1)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def clear_cell(row, col)
|
329
|
+
fill_cells row, col
|
330
|
+
|
331
|
+
unless @data[row][col].blank?
|
332
|
+
raise StandardError.new('placeholders cannot be cleared') if @data[row][col] == :span_placeholder
|
333
|
+
|
334
|
+
if @data[row][col].is_a? Hash
|
335
|
+
options = @data[row][col][:options] || { }
|
336
|
+
rspan = options[:rowspan] || 1
|
337
|
+
cspan = options[:colspan] || 1
|
338
|
+
|
339
|
+
# clear all the cells covered by the previous value.
|
340
|
+
(0...rspan).each do |r|
|
341
|
+
(0...cspan).each do |c|
|
342
|
+
@data[row + r][col + c] = ''
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
else
|
347
|
+
@data[row][col] = ''
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def set_cell(val, set_row = nil, set_col = nil, options = {})
|
353
|
+
row = set_row || @row_offset
|
354
|
+
col = set_col || @col_offset
|
355
|
+
|
356
|
+
clear_cell row, col
|
357
|
+
|
358
|
+
if options.empty?
|
359
|
+
@data[row][col] = val
|
360
|
+
else
|
361
|
+
@data[row][col] = options.merge({ content: val })
|
362
|
+
end
|
363
|
+
|
364
|
+
rspan = options[:rowspan] || 1
|
365
|
+
cspan = options[:colspan] || 1
|
366
|
+
|
367
|
+
# fill in placeholders for the spans.
|
368
|
+
(1...cspan).each do |c|
|
369
|
+
set_cell(:span_placeholder, row, col + c)
|
370
|
+
end
|
371
|
+
(1...rspan).each do |r|
|
372
|
+
(0...cspan).each do |c|
|
373
|
+
set_cell(:span_placeholder, row + r, col + c)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
unless set_col
|
378
|
+
@col_offset += 1
|
379
|
+
# skip over placeholders to set the next column position.
|
380
|
+
while @data[row][@col_offset] == :span_placeholder
|
381
|
+
@col_offset += 1
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
# ensure that all 2nd level arrays are the same size.
|
387
|
+
def fix_row_widths
|
388
|
+
|
389
|
+
fill_cells(@row_offset - 1, 0)
|
390
|
+
|
391
|
+
max = 0
|
392
|
+
|
393
|
+
@data.each_with_index do |row|
|
394
|
+
max = row.length unless max >= row.length
|
395
|
+
end
|
396
|
+
|
397
|
+
@data.each_with_index do |row,idx|
|
398
|
+
if row.length < max
|
399
|
+
row = row + [ @base_cell_options.merge({content: ''}) ] * (max - row.length)
|
400
|
+
@data[idx] = row
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
|
406
|
+
end
|
407
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module BarkestCore
|
2
|
+
class SelfUpdateConfig
|
3
|
+
include ActiveModel::Model
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
attr_accessor :host, :user, :password
|
7
|
+
attr_writer :port
|
8
|
+
|
9
|
+
validates :host, presence: true
|
10
|
+
validates :user, presence: true
|
11
|
+
validates :password, presence: true
|
12
|
+
|
13
|
+
def to_h
|
14
|
+
{
|
15
|
+
host: host.to_s,
|
16
|
+
port: port,
|
17
|
+
user: user.to_s,
|
18
|
+
password: password.to_s,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def port
|
23
|
+
@port ||= 22
|
24
|
+
val = @port.to_s.to_i
|
25
|
+
(1...65536).include?(val) ? val : 22
|
26
|
+
end
|
27
|
+
|
28
|
+
def save
|
29
|
+
SystemConfig.set :self_update, to_h, true
|
30
|
+
end
|
31
|
+
|
32
|
+
def SelfUpdateConfig.load
|
33
|
+
SelfUpdateConfig.new SystemConfig.get(:self_update)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|