mega_bar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +31 -0
  4. data/Rakefile +23 -0
  5. data/app/assets/javascripts/mega_bar/application.js +13 -0
  6. data/app/assets/stylesheets/mega_bar/application.css +15 -0
  7. data/app/controllers/mega_bar/application_controller.rb +28 -0
  8. data/app/controllers/mega_bar/checkboxes_controller.rb +19 -0
  9. data/app/controllers/mega_bar/field_displays_controller.rb +11 -0
  10. data/app/controllers/mega_bar/fields_controller.rb +11 -0
  11. data/app/controllers/mega_bar/grid_html.rb +27 -0
  12. data/app/controllers/mega_bar/mega_bar_concern.rb +169 -0
  13. data/app/controllers/mega_bar/model_displays_controller.rb +11 -0
  14. data/app/controllers/mega_bar/models_controller.rb +14 -0
  15. data/app/controllers/mega_bar/profile_table.rb +27 -0
  16. data/app/controllers/mega_bar/radio_buttons_controller.rb +18 -0
  17. data/app/controllers/mega_bar/records_formats_controller.rb +10 -0
  18. data/app/controllers/mega_bar/selects_controller.rb +12 -0
  19. data/app/controllers/mega_bar/testers_controller.rb +11 -0
  20. data/app/controllers/mega_bar/tests_controller.rb +5 -0
  21. data/app/controllers/mega_bar/textboxes_controller.rb +11 -0
  22. data/app/controllers/mega_bar/textreads_controller.rb +10 -0
  23. data/app/controllers/mega_bar/tmp_field_displays_controller.rb +18 -0
  24. data/app/controllers/mega_bar/tmp_fields_controller.rb +18 -0
  25. data/app/controllers/mega_bar/tmp_model_displays_controller.rb +18 -0
  26. data/app/controllers/mega_bar/tmp_models_controller.rb +16 -0
  27. data/app/controllers/mega_bar/tmp_records_formats_controller.rb +18 -0
  28. data/app/controllers/mega_bar/tmp_selects_controller.rb +18 -0
  29. data/app/controllers/mega_bar/tmp_textboxes_controller.rb +18 -0
  30. data/app/controllers/mega_bar/tmp_textreads_controller.rb +18 -0
  31. data/app/helpers/mega_bar/application_helper.rb +41 -0
  32. data/app/helpers/mega_bar/fields_helper.rb +13 -0
  33. data/app/helpers/mega_bar/models_helper.rb +13 -0
  34. data/app/models/mega_bar/checkbox.rb +8 -0
  35. data/app/models/mega_bar/field.rb +31 -0
  36. data/app/models/mega_bar/field_display.rb +25 -0
  37. data/app/models/mega_bar/mega_bar_model_concern.rb +20 -0
  38. data/app/models/mega_bar/model.rb +35 -0
  39. data/app/models/mega_bar/model_display.rb +10 -0
  40. data/app/models/mega_bar/radio_button.rb +6 -0
  41. data/app/models/mega_bar/records_format.rb +5 -0
  42. data/app/models/mega_bar/select.rb +9 -0
  43. data/app/models/mega_bar/test.rb +2 -0
  44. data/app/models/mega_bar/tester.rb +5 -0
  45. data/app/models/mega_bar/textarea.rb +9 -0
  46. data/app/models/mega_bar/textbox.rb +8 -0
  47. data/app/models/mega_bar/textread.rb +9 -0
  48. data/app/models/mega_bar/tmp_field.rb +6 -0
  49. data/app/models/mega_bar/tmp_field_display.rb +6 -0
  50. data/app/models/mega_bar/tmp_model.rb +6 -0
  51. data/app/models/mega_bar/tmp_model_display.rb +6 -0
  52. data/app/models/mega_bar/tmp_records_format.rb +6 -0
  53. data/app/models/mega_bar/tmp_select.rb +6 -0
  54. data/app/models/mega_bar/tmp_textbox.rb +6 -0
  55. data/app/models/mega_bar/tmp_textread.rb +6 -0
  56. data/app/views/mega_bar/application/_hello.html.erb +1 -0
  57. data/app/views/mega_bar/application/_mega_bar_read.html.erb +38 -0
  58. data/app/views/mega_bar/application/_mega_bar_write.html.erb +27 -0
  59. data/app/views/mega_bar/application/mega_bar.html.erb +62 -0
  60. data/app/views/textboxes/_form.html.erb +0 -0
  61. data/app/views/textboxes/edit.html.erb +0 -0
  62. data/app/views/textboxes/index.html.erb +0 -0
  63. data/app/views/textboxes/index.json.jbuilder +4 -0
  64. data/app/views/textboxes/new.html.erb +0 -0
  65. data/app/views/textboxes/show.html.erb +5 -0
  66. data/app/views/textboxes/show.json.jbuilder +1 -0
  67. data/app/views/textreads/_form.html.erb +0 -0
  68. data/app/views/textreads/edit.html.erb +0 -0
  69. data/app/views/textreads/index.html.erb +0 -0
  70. data/app/views/textreads/index.json.jbuilder +4 -0
  71. data/app/views/textreads/new.html.erb +0 -0
  72. data/app/views/textreads/show.html.erb +1 -0
  73. data/app/views/textreads/show.html.erb.orig.rhtml +0 -0
  74. data/app/views/textreads/show.json.jbuilder +1 -0
  75. data/config/routes.rb +30 -0
  76. data/db/mega_bar.seeds.rb +814 -0
  77. data/db/migrate/20140505150251_create_models.rb +12 -0
  78. data/db/migrate/20140505174947_create_model_displays.rb +11 -0
  79. data/db/migrate/20140505195607_create_records_formats.rb +11 -0
  80. data/db/migrate/20140505211530_create_textreads.rb +12 -0
  81. data/db/migrate/20140505214403_create_textboxes.rb +10 -0
  82. data/db/migrate/20140521220256_create_fields.rb +12 -0
  83. data/db/migrate/20140521222528_create_field_displays.rb +12 -0
  84. data/db/migrate/20140523160810_create_selects.rb +16 -0
  85. data/db/migrate/20140523200921_create_testers.rb +11 -0
  86. data/db/migrate/20140618170624_create_tests.rb +9 -0
  87. data/db/migrate/20141227235653_create_tmp_models.rb +11 -0
  88. data/db/migrate/20141228061208_create_mega_bar_tmp_fields.rb +12 -0
  89. data/db/migrate/20141228163900_create_mega_bar_tmp_model_displays.rb +11 -0
  90. data/db/migrate/20141228163956_create_mega_bar_tmp_field_displays.rb +11 -0
  91. data/db/migrate/20141228164052_create_mega_bar_tmp_records_formats.rb +10 -0
  92. data/db/migrate/20141228164245_create_mega_bar_tmp_textboxes.rb +10 -0
  93. data/db/migrate/20141228164314_create_mega_bar_tmp_textreads.rb +12 -0
  94. data/db/migrate/20141228164350_create_mega_bar_tmp_selects.rb +16 -0
  95. data/db/migrate/20141229173832_create_mega_bar_checkboxes.mega_bar.rb +8 -0
  96. data/db/migrate/20141229180849_create_mega_bar_radio_buttons.mega_bar.rb +8 -0
  97. data/db/migrate/20141230171751_create_mega_bar_textareas.mega_bar.rb +8 -0
  98. data/db/migrate/20141230173142_create_mega_bar_checkboxes.mega_bar.rb +9 -0
  99. data/lib/generators/mega_bar/mega_bar/USAGE +8 -0
  100. data/lib/generators/mega_bar/mega_bar/mega_bar_generator.rb +91 -0
  101. data/lib/generators/mega_bar/mega_bar/templates/generic_controller.rb +18 -0
  102. data/lib/generators/mega_bar/mega_bar/templates/generic_model.rb +6 -0
  103. data/lib/generators/mega_bar/mega_bar_fields/USAGE +8 -0
  104. data/lib/generators/mega_bar/mega_bar_fields/mega_bar_fields_generator.rb +13 -0
  105. data/lib/generators/mega_bar/mega_bar_fields/templates/generic_controller.rb +15 -0
  106. data/lib/generators/mega_bar/mega_bar_fields/templates/generic_model.rb +6 -0
  107. data/lib/mega_bar/engine.rb +15 -0
  108. data/lib/mega_bar/generators/mega_bar_generator.rb +6 -0
  109. data/lib/mega_bar/version.rb +3 -0
  110. data/lib/mega_bar.rb +4 -0
  111. data/lib/tasks/mega_bar_tasks.rake +270 -0
  112. metadata +393 -0
@@ -0,0 +1,12 @@
1
+ class CreateModels < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_models do |t|
4
+ t.string :classname
5
+ t.string :schema
6
+ t.string :tablename
7
+ t.string :name
8
+ t.string :default_sort_field
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateModelDisplays < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_model_displays do |t|
4
+ t.integer :model_id
5
+ t.string :format
6
+ t.string :action
7
+ t.string :header
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class CreateRecordsFormats < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_records_formats do |t|
4
+ t.string :name
5
+ t.string :classname
6
+ t.string :type
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreateTextreads < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_textreads do |t|
4
+ t.integer :field_display_id
5
+ t.integer :truncation
6
+ t.text :truncation_format
7
+ t.text :transformation
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class CreateTextboxes < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_textboxes do |t|
4
+ t.integer :field_display_id
5
+ t.integer :size
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ class CreateFields < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_fields do |t|
4
+ t.integer :model_id
5
+ t.string :schema
6
+ t.string :tablename
7
+ t.string :field
8
+ t.string :default_value
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class CreateFieldDisplays < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_field_displays do |t|
4
+ t.integer :field_id
5
+ t.string :format
6
+ t.string :action
7
+ t.string :header
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ class CreateSelects < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_selects do |t|
4
+ t.integer :field_display_id
5
+ t.integer :model_id
6
+ t.integer :field_id
7
+ t.string :collection
8
+ t.string :value_method
9
+ t.string :text_method
10
+ t.integer :data_size
11
+ t.string :include_blank
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ class CreateTesters < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_testers do |t|
4
+ t.string :one
5
+ t.string :two
6
+ t.string :three
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTests < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tests do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateTmpModels < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tmp_models do |t|
4
+ t.string :classname
5
+ t.string :schema
6
+ t.string :tablename
7
+ t.string :name
8
+ t.string :default_sort_field
9
+ t.timestamps end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreateMegaBarTmpFields < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tmp_fields do |t|
4
+ t.integer :model_id
5
+ t.string :schema
6
+ t.string :tablename
7
+ t.string :field
8
+ t.string :default_value
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateMegaBarTmpModelDisplays < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tmp_model_displays do |t|
4
+ t.integer :model_id
5
+ t.string :format
6
+ t.string :action
7
+ t.string :header
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class CreateMegaBarTmpFieldDisplays < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tmp_field_displays do |t|
4
+ t.integer :field_id
5
+ t.string :format
6
+ t.string :action
7
+ t.string :header
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ class CreateMegaBarTmpRecordsFormats < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tmp_records_formats do |t|
4
+ t.string :name
5
+ t.string :classname
6
+ t.string :type
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateMegaBarTmpTextboxes < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tmp_textboxes do |t|
4
+ t.integer :field_display_id
5
+ t.integer :size
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ class CreateMegaBarTmpTextreads < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tmp_textreads do |t|
4
+ t.integer :field_display_id
5
+ t.integer :truncation
6
+ t.text :truncation_format
7
+ t.text :transformation
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ class CreateMegaBarTmpSelects < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_tmp_selects do |t|
4
+ t.integer :field_display_id
5
+ t.integer :model_id
6
+ t.integer :field_id
7
+ t.string :collection
8
+ t.string :value_method
9
+ t.string :text_method
10
+ t.integer :data_size
11
+ t.string :include_blank
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ class CreateMegaBarCheckboxes < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_checkboxes do |t|
4
+ t.datetime :created_at
5
+ t.datetime :updated_at
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class CreateMegaBarRadioButtons < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_radio_buttons do |t|
4
+ t.datetime :created_at
5
+ t.datetime :updated_at
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class CreateMegaBarTextareas < ActiveRecord::Migration
2
+ def change
3
+ create_table :mega_bar_textareas do |t|
4
+ t.datetime :created_at
5
+ t.datetime :updated_at
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ # This migration comes from mega_bar (originally 20141229173832)
2
+ class CreateMegaBarCheckboxes < ActiveRecord::Migration
3
+ def change
4
+ create_table :mega_bar_checkboxes do |t|
5
+ t.datetime :created_at
6
+ t.datetime :updated_at
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate mega_bar Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,91 @@
1
+ module MegaBar
2
+ class MegaBarGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :filename, type: :string
5
+ argument :model_id, type: :string
6
+
7
+ # in generators, all public methods are run. Weird, huh?
8
+
9
+ def create_controller_file
10
+ template "generic_controller.rb", "#{the_controller_file_name}.rb"
11
+ if the_module_name
12
+ # template "generic_controller.rb", "tmp_#{the_controller_file_name}.rb"
13
+ end
14
+
15
+ end
16
+ def create_model_file
17
+ template "generic_model.rb", "#{the_model_file_name}"
18
+ if the_module_name
19
+ # template "generic_model.rb", "Tmp#{the_model_file_name}.rb"
20
+ end
21
+ end
22
+ def generate_migration
23
+ if the_module_name
24
+ generate 'migration create_' + the_module_name + '_' + the_table_name + ' created_at:datetime updated_at:datetime'
25
+ # generate 'migration create_tmp_' + the_module_name + '_' + the_table_name + ' created_at:datetime updated_at:datetime'
26
+ else
27
+ generate 'migration create_' + the_table_name + ' created_at:datetime updated_at:datetime'
28
+ end
29
+
30
+ end
31
+ def route
32
+
33
+ line = ' ##### MEGABAR END'
34
+ text = File.read('config/routes.rb')
35
+ new_contents = text.gsub( /(#{Regexp.escape(line)})/mi, 'resource :' + the_route_name + "\n #{line}\n")
36
+ # To write changes to the file, use:
37
+ File.open('config/routes.rb', "w") {|file| file.puts new_contents }
38
+ end
39
+
40
+ private
41
+
42
+ def the_file_name
43
+ if filename.include? '::'
44
+ return filename[filename.index('::')+2..-1]
45
+ else
46
+ return filename
47
+ end
48
+ end
49
+
50
+ def the_model_file_name
51
+ if the_module_name
52
+ 'app/models/' + the_module_name.underscore + '/' + the_file_name.to_s.singularize.underscore + '.rb'
53
+ else
54
+ 'app/models/' + the_file_name.to_s.singularize.underscore + '.rb'
55
+ end
56
+ end
57
+
58
+ def the_model_name
59
+ the_file_name.classify
60
+ end
61
+
62
+ def the_controller_file_name
63
+ if the_module_name
64
+ 'app/controllers/' + the_module_name.underscore + '/' + the_file_name.pluralize.underscore + "_controller"
65
+ else
66
+ 'app/controllers/' + the_file_name.pluralize.underscore + "_controller"
67
+ end
68
+ end
69
+
70
+ def the_controller_name
71
+ the_file_name.classify.pluralize + 'Controller'
72
+ end
73
+
74
+ def the_table_name
75
+ the_file_name.pluralize
76
+ end
77
+
78
+ def the_module_name
79
+ if filename.include? '::'
80
+ return filename[0..filename.index('::')-1]
81
+ else
82
+ return nil
83
+ end
84
+ end
85
+
86
+ def the_route_name
87
+ the_file_name.pluralize.underscore
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,18 @@
1
+ <% if the_module_name %>
2
+ module <%=the_module_name%>
3
+ <% end %>class <%= the_controller_name %> < ApplicationController
4
+ include MegaBarConcern
5
+ before_action ->{ myinit <%= model_id %> }, only: [:index, :show, :edit, :new]
6
+
7
+
8
+ private
9
+ def _params
10
+ permits = []
11
+ controller_name.classify.constantize.attribute_names.each do |att|
12
+ permits << att unless ['id', 'created_at', 'updated_at'].include?(att)
13
+ end
14
+ params.require(controller_name.singularize).permit(permits)
15
+ end
16
+
17
+ <% if the_module_name %> end<% end %>
18
+ end
@@ -0,0 +1,6 @@
1
+ <% if the_module_name %>
2
+ module <%=the_module_name%>
3
+ <% end %>class <%= the_model_name %> < ActiveRecord::Base
4
+
5
+ <% if the_module_name %> end<% end %>
6
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ This will create a migration for adding a field to a table
3
+
4
+ Example:
5
+ rails generate mega_bar:mega_bar_fields tablename fieldname type
6
+
7
+ This will create a new migration.
8
+
@@ -0,0 +1,13 @@
1
+ module MegaBar
2
+ class MegaBarFieldsGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :tablename, type: :string
5
+ argument :fieldname, type: :string
6
+ argument :fieldtype, type: :string
7
+
8
+ def generate_migration
9
+ generate 'migration add_' + fieldname + '_to_' + tablename + ' ' + fieldname + ':' + fieldtype
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ <% if the_module_name %>
2
+ module <%=the_module_name%>
3
+ <% end %>class <%= the_controller_name %> < ApplicationController
4
+ include MegaBarConcern
5
+ before_action ->{ myinit <%= model_id %> }, only: [:index, :show, :edit, :new]
6
+
7
+
8
+
9
+ private
10
+ # Never trust parameters from the scary internet, only allow the white list through.
11
+ def _params
12
+ params.require(:textbox).permit()
13
+ end
14
+ <% if the_module_name %> end<% end %>
15
+ end
@@ -0,0 +1,6 @@
1
+ <% if the_module_name %>
2
+ module <%=the_module_name%>
3
+ <% end %>class <%= the_model_name %> < ActiveRecord::Base
4
+
5
+ <% if the_module_name %> end<% end %>
6
+ end
@@ -0,0 +1,15 @@
1
+ module MegaBar
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace MegaBar
4
+
5
+
6
+ config.generators do |g|
7
+ g.test_framework :rspec
8
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
9
+ end
10
+ ### taskrabbit: http://tech.taskrabbit.com/blog/2014/02/11/rails-4-engines/
11
+ ### http://pivotallabs.com/leave-your-migrations-in-your-rails-engines/
12
+
13
+
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module MegaBar
2
+ class MegaBarGenerator < Rails::Generators::Base
3
+ def create_scaffold
4
+ create_file "config/initializers/initializer.rb", "# Add initialization content here"
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module MegaBar
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mega_bar.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "mega_bar/engine"
2
+
3
+ module MegaBar
4
+ end