script_core 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -1
- data/.gitignore +15 -1
- data/.rubocop.yml +10 -2
- data/.ruby-version +1 -1
- data/.travis.yml +6 -0
- data/Gemfile +32 -0
- data/README.md +169 -6
- data/Rakefile +11 -0
- data/Vagrantfile +1 -1
- data/bin/rails +25 -0
- data/bootstrap.sh +2 -3
- data/dev.yml +4 -4
- data/ext/enterprise_script_service/Rakefile +5 -4
- data/ext/enterprise_script_service/mruby_config.rb +1 -0
- data/lib/script_core.rb +17 -15
- data/lib/script_core/engine.rb +1 -0
- data/lib/script_core/executable.rb +1 -1
- data/lib/script_core/railtie.rb +8 -0
- data/lib/script_core/spawner.rb +1 -0
- data/lib/script_core/version.rb +1 -1
- data/lib/tasks/mruby/engine.gembox.example +19 -0
- data/lib/tasks/mruby/lib/.keep +0 -0
- data/lib/tasks/script_core.rake +111 -0
- data/script/regression +7 -5
- data/script_core.gemspec +2 -2
- data/spec/dummy/Rakefile +8 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.es6 +56 -0
- data/spec/dummy/app/assets/stylesheets/application.scss +65 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/fields/application_controller.rb +25 -0
- data/spec/dummy/app/controllers/fields/options_controller.rb +26 -0
- data/spec/dummy/app/controllers/fields/validations_controller.rb +26 -0
- data/spec/dummy/app/controllers/forms/application_controller.rb +14 -0
- data/spec/dummy/app/controllers/forms/fields_controller.rb +56 -0
- data/spec/dummy/app/controllers/forms/formulas/application_controller.rb +19 -0
- data/spec/dummy/app/controllers/forms/formulas/playgrounds_controller.rb +29 -0
- data/spec/dummy/app/controllers/forms/formulas_controller.rb +56 -0
- data/spec/dummy/app/controllers/forms_controller.rb +58 -0
- data/spec/dummy/app/controllers/home_controller.rb +7 -0
- data/spec/dummy/app/controllers/nested_forms/application_controller.rb +12 -0
- data/spec/dummy/app/controllers/nested_forms/fields_controller.rb +50 -0
- data/spec/dummy/app/controllers/playgrounds_controller.rb +29 -0
- data/spec/dummy/app/decorators/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +21 -0
- data/spec/dummy/app/helpers/fields_helper.rb +32 -0
- data/spec/dummy/app/helpers/forms_helper.rb +14 -0
- data/spec/dummy/app/jobs/application_job.rb +4 -0
- data/spec/dummy/app/lib/script_engine.rb +22 -0
- data/spec/dummy/app/models/application_record.rb +8 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/concerns/acts_as_default_value.rb +152 -0
- data/spec/dummy/app/models/concerns/enum_attribute_localizable.rb +32 -0
- data/spec/dummy/app/models/concerns/fields/validations/acceptance.rb +18 -0
- data/spec/dummy/app/models/concerns/fields/validations/confirmation.rb +18 -0
- data/spec/dummy/app/models/concerns/fields/validations/exclusion.rb +35 -0
- data/spec/dummy/app/models/concerns/fields/validations/format.rb +45 -0
- data/spec/dummy/app/models/concerns/fields/validations/inclusion.rb +35 -0
- data/spec/dummy/app/models/concerns/fields/validations/length.rb +59 -0
- data/spec/dummy/app/models/concerns/fields/validations/numericality.rb +56 -0
- data/spec/dummy/app/models/concerns/fields/validations/presence.rb +18 -0
- data/spec/dummy/app/models/concerns/form_core/acts_as_default_value.rb +143 -0
- data/spec/dummy/app/models/field.rb +67 -0
- data/spec/dummy/app/models/field_options.rb +90 -0
- data/spec/dummy/app/models/fields.rb +10 -0
- data/spec/dummy/app/models/fields/boolean_field.rb +12 -0
- data/spec/dummy/app/models/fields/decimal_field.rb +12 -0
- data/spec/dummy/app/models/fields/integer_field.rb +20 -0
- data/spec/dummy/app/models/fields/multiple_nested_form_field.rb +35 -0
- data/spec/dummy/app/models/fields/nested_form_field.rb +37 -0
- data/spec/dummy/app/models/fields/options/boolean_field.rb +6 -0
- data/spec/dummy/app/models/fields/options/decimal_field.rb +12 -0
- data/spec/dummy/app/models/fields/options/integer_field.rb +13 -0
- data/spec/dummy/app/models/fields/options/multiple_nested_form_field.rb +6 -0
- data/spec/dummy/app/models/fields/options/nested_form_field.rb +6 -0
- data/spec/dummy/app/models/fields/options/text_field.rb +7 -0
- data/spec/dummy/app/models/fields/text_field.rb +12 -0
- data/spec/dummy/app/models/fields/validations/boolean_field.rb +7 -0
- data/spec/dummy/app/models/fields/validations/decimal_field.rb +8 -0
- data/spec/dummy/app/models/fields/validations/integer_field.rb +8 -0
- data/spec/dummy/app/models/fields/validations/multiple_nested_form_field.rb +8 -0
- data/spec/dummy/app/models/fields/validations/nested_form_field.rb +7 -0
- data/spec/dummy/app/models/fields/validations/text_field.rb +9 -0
- data/spec/dummy/app/models/form.rb +8 -0
- data/spec/dummy/app/models/formula.rb +8 -0
- data/spec/dummy/app/models/metal_form.rb +9 -0
- data/spec/dummy/app/models/nested_form.rb +5 -0
- data/spec/dummy/app/models/virtual_model.rb +23 -0
- data/spec/dummy/app/presenters/application_presenter.rb +11 -0
- data/spec/dummy/app/presenters/concerns/fields/presenter_for_number_field.rb +36 -0
- data/spec/dummy/app/presenters/fields/boolean_field_presenter.rb +13 -0
- data/spec/dummy/app/presenters/fields/composite_field_presenter.rb +13 -0
- data/spec/dummy/app/presenters/fields/decimal_field_presenter.rb +7 -0
- data/spec/dummy/app/presenters/fields/field_presenter.rb +44 -0
- data/spec/dummy/app/presenters/fields/integer_field_presenter.rb +11 -0
- data/spec/dummy/app/presenters/fields/multiple_nested_form_field_presenter.rb +9 -0
- data/spec/dummy/app/presenters/fields/nested_form_field_presenter.rb +9 -0
- data/spec/dummy/app/presenters/fields/text_field_presenter.rb +10 -0
- data/spec/dummy/app/views/_form_core/field_options/_decimal_field.html.erb +9 -0
- data/spec/dummy/app/views/_form_core/field_options/_integer_field.html.erb +10 -0
- data/spec/dummy/app/views/_form_core/field_options/_text_field.html.erb +12 -0
- data/spec/dummy/app/views/_form_core/fields/_boolean_field.html.erb +11 -0
- data/spec/dummy/app/views/_form_core/fields/_decimal_field.html.erb +9 -0
- data/spec/dummy/app/views/_form_core/fields/_integer_field.html.erb +9 -0
- data/spec/dummy/app/views/_form_core/fields/_multiple_nested_form_field.html.erb +23 -0
- data/spec/dummy/app/views/_form_core/fields/_nested_form.html.erb +37 -0
- data/spec/dummy/app/views/_form_core/fields/_nested_form_field.html.erb +42 -0
- data/spec/dummy/app/views/_form_core/fields/_text_field.html.erb +13 -0
- data/spec/dummy/app/views/_form_core/preview/_form.html.erb +17 -0
- data/spec/dummy/app/views/_form_core/preview/_nested_form.html.erb +22 -0
- data/spec/dummy/app/views/_form_core/render/_form.html.erb +39 -0
- data/spec/dummy/app/views/_form_core/validations/_acceptance.html.erb +12 -0
- data/spec/dummy/app/views/_form_core/validations/_confirmation.html.erb +12 -0
- data/spec/dummy/app/views/_form_core/validations/_exclusion.html.erb +2 -0
- data/spec/dummy/app/views/_form_core/validations/_format.html.erb +37 -0
- data/spec/dummy/app/views/_form_core/validations/_inclusion.html.erb +2 -0
- data/spec/dummy/app/views/_form_core/validations/_length.html.erb +44 -0
- data/spec/dummy/app/views/_form_core/validations/_numericality.html.erb +45 -0
- data/spec/dummy/app/views/_form_core/validations/_presence.html.erb +12 -0
- data/spec/dummy/app/views/fields/options/_form.html.erb +29 -0
- data/spec/dummy/app/views/fields/options/edit.html.erb +6 -0
- data/spec/dummy/app/views/fields/validations/_form.html.erb +34 -0
- data/spec/dummy/app/views/fields/validations/edit.html.erb +6 -0
- data/spec/dummy/app/views/forms/_form.html.erb +41 -0
- data/spec/dummy/app/views/forms/edit.html.erb +6 -0
- data/spec/dummy/app/views/forms/fields/_form.html.erb +71 -0
- data/spec/dummy/app/views/forms/fields/edit.html.erb +6 -0
- data/spec/dummy/app/views/forms/fields/index.html.erb +42 -0
- data/spec/dummy/app/views/forms/fields/new.html.erb +6 -0
- data/spec/dummy/app/views/forms/formulas/_form.html.erb +41 -0
- data/spec/dummy/app/views/forms/formulas/edit.html.erb +6 -0
- data/spec/dummy/app/views/forms/formulas/index.html.erb +28 -0
- data/spec/dummy/app/views/forms/formulas/new.html.erb +6 -0
- data/spec/dummy/app/views/forms/formulas/playgrounds/create.html.erb +48 -0
- data/spec/dummy/app/views/forms/formulas/playgrounds/show.html.erb +14 -0
- data/spec/dummy/app/views/forms/index.html.erb +31 -0
- data/spec/dummy/app/views/forms/new.html.erb +6 -0
- data/spec/dummy/app/views/home/index.html.erb +5 -0
- data/spec/dummy/app/views/layouts/_alert.html.erb +4 -0
- data/spec/dummy/app/views/layouts/_footer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/_nav.html.erb +11 -0
- data/spec/dummy/app/views/layouts/_notice.html.erb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +25 -0
- data/spec/dummy/app/views/layouts/forms.html.erb +33 -0
- data/spec/dummy/app/views/nested_forms/fields/_form.html.erb +68 -0
- data/spec/dummy/app/views/nested_forms/fields/edit.html.erb +6 -0
- data/spec/dummy/app/views/nested_forms/fields/index.html.erb +39 -0
- data/spec/dummy/app/views/nested_forms/fields/new.html.erb +6 -0
- data/spec/dummy/app/views/playgrounds/_form.html.erb +13 -0
- data/spec/dummy/app/views/playgrounds/create.html.erb +51 -0
- data/spec/dummy/app/views/playgrounds/show.html.erb +7 -0
- data/spec/dummy/bin/bundle +5 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/bin/setup +40 -0
- data/spec/dummy/bin/update +35 -0
- data/spec/dummy/bin/yarn +13 -0
- data/spec/dummy/config.ru +7 -0
- data/spec/dummy/config/application.rb +35 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +58 -0
- data/spec/dummy/config/environments/production.rb +85 -0
- data/spec/dummy/config/environments/test.rb +41 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
- data/spec/dummy/config/initializers/assets.rb +16 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +27 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy/config/initializers/form_core.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +18 -0
- data/spec/dummy/config/initializers/mime_types.rb +6 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +36 -0
- data/spec/dummy/config/routes.rb +31 -0
- data/spec/dummy/config/spring.rb +8 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/migrate/20180916202025_create_forms.form_core.rb +12 -0
- data/spec/dummy/db/migrate/20180916202026_add_columns_to_forms.rb +10 -0
- data/spec/dummy/db/migrate/20180916202027_add_attachable_to_forms.rb +9 -0
- data/spec/dummy/db/migrate/20180916202030_create_fields.form_core.rb +17 -0
- data/spec/dummy/db/migrate/20180916202121_add_columns_to_fields.rb +10 -0
- data/spec/dummy/db/migrate/20180916202124_add_position_to_fields.rb +9 -0
- data/spec/dummy/db/migrate/20181111111412_create_formulas.rb +13 -0
- data/spec/dummy/db/schema.rb +52 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/monkey_patches/active_support.rb +3 -0
- data/spec/dummy/lib/monkey_patches/active_support/concern+prependable.rb +28 -0
- data/spec/dummy/lib/monkey_patches/big_decimal.rb +8 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/mruby/engine.gembox +19 -0
- data/spec/dummy/mruby/lib/.keep +0 -0
- data/spec/dummy/mruby/lib/core_ext.rb +62 -0
- data/spec/dummy/mruby/lib/harden.rb +1 -0
- data/spec/dummy/mruby/lib/input.rb +20 -0
- data/spec/dummy/mruby/lib/io.rb +19 -0
- data/spec/dummy/mruby/lib/output.rb +35 -0
- data/spec/dummy/mruby/lib/script_kernel.rb +12 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/dummy/test/controllers/.keep +0 -0
- data/spec/dummy/test/fixtures/.keep +0 -0
- data/spec/dummy/test/models/.keep +0 -0
- data/spec/script_core_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- metadata +199 -5
- data/circle.yml +0 -9
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Fields::OptionsController < Fields::ApplicationController
|
4
|
+
before_action :set_options
|
5
|
+
|
6
|
+
def edit; end
|
7
|
+
|
8
|
+
def update
|
9
|
+
@options.assign_attributes(options_params)
|
10
|
+
if @options.valid? && @field.save(validate: false)
|
11
|
+
redirect_to fields_url, notice: "Field was successfully updated."
|
12
|
+
else
|
13
|
+
render :edit
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def set_options
|
20
|
+
@options = @field.options
|
21
|
+
end
|
22
|
+
|
23
|
+
def options_params
|
24
|
+
params.fetch(:options, {}).permit!
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Fields::ValidationsController < Fields::ApplicationController
|
4
|
+
before_action :set_validations
|
5
|
+
|
6
|
+
def edit; end
|
7
|
+
|
8
|
+
def update
|
9
|
+
@validations.assign_attributes(validations_params)
|
10
|
+
if @validations.valid? && @field.save(validate: false)
|
11
|
+
redirect_to fields_url, notice: "Field was successfully updated."
|
12
|
+
else
|
13
|
+
render :edit
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def set_validations
|
20
|
+
@validations = @field.validations
|
21
|
+
end
|
22
|
+
|
23
|
+
def validations_params
|
24
|
+
params.fetch(:validations, {}).permit!
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Forms::ApplicationController < ApplicationController
|
4
|
+
layout "forms"
|
5
|
+
|
6
|
+
before_action :set_form
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
# Use callbacks to share common setup or constraints between actions.
|
11
|
+
def set_form
|
12
|
+
@form = Form.find(params[:form_id])
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Forms::FieldsController < Forms::ApplicationController
|
4
|
+
before_action :set_field, only: %i[show edit update destroy]
|
5
|
+
|
6
|
+
# GET /forms/1/fields
|
7
|
+
def index
|
8
|
+
@fields = @form.fields.all
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /forms/fields/new
|
12
|
+
def new
|
13
|
+
@field = @form.fields.build
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /forms/1/fields/1/edit
|
17
|
+
def edit; end
|
18
|
+
|
19
|
+
# POST /forms/1/fields
|
20
|
+
def create
|
21
|
+
@field = @form.fields.build(field_params)
|
22
|
+
|
23
|
+
if @field.save
|
24
|
+
redirect_to form_fields_url(@form), notice: "Field was successfully created."
|
25
|
+
else
|
26
|
+
render :new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# PATCH/PUT /forms/1/fields/1
|
31
|
+
def update
|
32
|
+
if @field.update(field_params)
|
33
|
+
redirect_to form_fields_url(@form), notice: "Field was successfully updated."
|
34
|
+
else
|
35
|
+
render :edit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# DELETE /forms/1/fields/1
|
40
|
+
def destroy
|
41
|
+
@field.destroy
|
42
|
+
redirect_to form_fields_url(@form), notice: "Field was successfully destroyed."
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Use callbacks to share common setup or constraints between actions.
|
48
|
+
def set_field
|
49
|
+
@field = @form.fields.find(params[:id])
|
50
|
+
end
|
51
|
+
|
52
|
+
# Only allow a trusted parameter "white list" through.
|
53
|
+
def field_params
|
54
|
+
params.fetch(:field, {}).permit(:name, :label, :hint, :accessibility, :type)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Forms
|
4
|
+
class Formulas::ApplicationController < ApplicationController
|
5
|
+
before_action :set_form
|
6
|
+
before_action :set_formula
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
# Use callbacks to share common setup or constraints between actions.
|
11
|
+
def set_form
|
12
|
+
@form = Form.find(params[:form_id])
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_formula
|
16
|
+
@formula = @form.formulas.find(params[:formula_id])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Forms
|
4
|
+
class Formulas::PlaygroundsController < Forms::Formulas::ApplicationController
|
5
|
+
before_action :set_virtual_model
|
6
|
+
|
7
|
+
def show
|
8
|
+
@form_record = @virtual_model.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@form_record = @virtual_model.new form_record_params
|
13
|
+
return render :show unless @form_record.valid?
|
14
|
+
|
15
|
+
@input = @form_record.serializable_hash
|
16
|
+
@result = ScriptEngine.eval @formula.body, input: @input
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def set_virtual_model
|
22
|
+
@virtual_model = @form.to_virtual_model
|
23
|
+
end
|
24
|
+
|
25
|
+
def form_record_params
|
26
|
+
params.fetch(:form_record, {}).permit!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Forms::FormulasController < Forms::ApplicationController
|
4
|
+
before_action :set_formula, only: %i[show edit update destroy]
|
5
|
+
|
6
|
+
# GET /forms/1/formulas
|
7
|
+
def index
|
8
|
+
@formulas = @form.formulas.all
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /forms/formulas/new
|
12
|
+
def new
|
13
|
+
@formula = @form.formulas.build
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /forms/1/formulas/1/edit
|
17
|
+
def edit; end
|
18
|
+
|
19
|
+
# POST /forms/1/formulas
|
20
|
+
def create
|
21
|
+
@formula = @form.formulas.build(formula_params)
|
22
|
+
|
23
|
+
if @formula.save
|
24
|
+
redirect_to form_formulas_url(@form), notice: "formula was successfully created."
|
25
|
+
else
|
26
|
+
render :new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# PATCH/PUT /forms/1/formulas/1
|
31
|
+
def update
|
32
|
+
if @formula.update(formula_params)
|
33
|
+
redirect_to form_formulas_url(@form), notice: "formula was successfully updated."
|
34
|
+
else
|
35
|
+
render :edit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# DELETE /forms/1/formulas/1
|
40
|
+
def destroy
|
41
|
+
@formula.destroy
|
42
|
+
redirect_to form_formulas_url(@form), notice: "formula was successfully destroyed."
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Use callbacks to share common setup or constraints between actions.
|
48
|
+
def set_formula
|
49
|
+
@formula = @form.formulas.find(params[:id])
|
50
|
+
end
|
51
|
+
|
52
|
+
# Only allow a trusted parameter "white list" through.
|
53
|
+
def formula_params
|
54
|
+
params.fetch(:formula, {}).permit(:name, :body)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FormsController < ApplicationController
|
4
|
+
layout "application"
|
5
|
+
|
6
|
+
before_action :set_form, only: %i[edit update destroy]
|
7
|
+
|
8
|
+
# GET /forms
|
9
|
+
def index
|
10
|
+
@forms = Form.all
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /forms/new
|
14
|
+
def new
|
15
|
+
@form = Form.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /forms/1/edit
|
19
|
+
def edit; end
|
20
|
+
|
21
|
+
# POST /forms
|
22
|
+
def create
|
23
|
+
@form = Form.new(form_params)
|
24
|
+
|
25
|
+
if @form.save
|
26
|
+
redirect_to form_fields_url(@form), notice: "Form was successfully created."
|
27
|
+
else
|
28
|
+
render :new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# PATCH/PUT /forms/1
|
33
|
+
def update
|
34
|
+
if @form.update(form_params)
|
35
|
+
redirect_to form_fields_url(@form), notice: "Form was successfully updated."
|
36
|
+
else
|
37
|
+
render :edit
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# DELETE /forms/1
|
42
|
+
def destroy
|
43
|
+
@form.destroy
|
44
|
+
redirect_to forms_url, notice: "Form was successfully destroyed."
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# Use callbacks to share common setup or constraints between actions.
|
50
|
+
def set_form
|
51
|
+
@form = Form.find(params[:id])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Only allow a trusted parameter "white list" through.
|
55
|
+
def form_params
|
56
|
+
params.fetch(:form, {}).permit(:title, :description)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class NestedForms::ApplicationController < ApplicationController
|
4
|
+
before_action :set_nested_form
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
# Use callbacks to share common setup or constraints between actions.
|
9
|
+
def set_nested_form
|
10
|
+
@nested_form = NestedForm.find(params[:nested_form_id])
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class NestedForms::FieldsController < NestedForms::ApplicationController
|
4
|
+
before_action :set_field, only: %i[show edit update destroy]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@fields = @nested_form.fields.all
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
@field = @nested_form.fields.build
|
12
|
+
end
|
13
|
+
|
14
|
+
def edit; end
|
15
|
+
|
16
|
+
def create
|
17
|
+
@field = @nested_form.fields.build(field_params)
|
18
|
+
|
19
|
+
if @field.save
|
20
|
+
redirect_to nested_form_fields_url(@nested_form), notice: "Field was successfully created."
|
21
|
+
else
|
22
|
+
render :new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
if @field.update(field_params)
|
28
|
+
redirect_to nested_form_fields_url(@nested_form), notice: "Field was successfully updated."
|
29
|
+
else
|
30
|
+
render :edit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def destroy
|
35
|
+
@field.destroy
|
36
|
+
redirect_to nested_form_fields_url(@nested_form), notice: "Field was successfully destroyed."
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Use callbacks to share common setup or constraints between actions.
|
42
|
+
def set_field
|
43
|
+
@field = @nested_form.fields.find(params[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
# Only allow a trusted parameter "white list" through.
|
47
|
+
def field_params
|
48
|
+
params.fetch(:field, {}).permit(:name, :label, :hint, :accessibility, :type)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class PlaygroundsController < ApplicationController
|
4
|
+
before_action :set_source
|
5
|
+
|
6
|
+
def show
|
7
|
+
@source = <<~CODE
|
8
|
+
puts "You can use `puts` to output strings to (fake) stdout for logging..."
|
9
|
+
puts "Call multiple absolutely OK!"
|
10
|
+
|
11
|
+
str = ""
|
12
|
+
(1..3).each do |i|
|
13
|
+
str += "Hello world!!! x\#{i}; "
|
14
|
+
end
|
15
|
+
|
16
|
+
set_output str
|
17
|
+
CODE
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
@result = ScriptEngine.eval @source
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def set_source
|
27
|
+
@source = params.fetch(:source, "")
|
28
|
+
end
|
29
|
+
end
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApplicationHelper
|
4
|
+
def options_for_enum_select(klass, attribute, selected = nil)
|
5
|
+
container = klass.public_send(attribute.to_s.pluralize).map do |k, v|
|
6
|
+
v ||= k
|
7
|
+
[klass.human_enum_value(attribute, k), v]
|
8
|
+
end
|
9
|
+
|
10
|
+
options_for_select(container, selected)
|
11
|
+
end
|
12
|
+
|
13
|
+
def present(model, options = {})
|
14
|
+
klass = options.delete(:presenter_class) || "#{model.class}Presenter".constantize
|
15
|
+
presenter = klass.new(model, self, options)
|
16
|
+
|
17
|
+
yield(presenter) if block_given?
|
18
|
+
|
19
|
+
presenter
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FieldsHelper
|
4
|
+
def options_for_field_types(selected: nil)
|
5
|
+
options_for_select(Field.descendants.map { |klass| [klass.model_name.human, klass.to_s] }, selected)
|
6
|
+
end
|
7
|
+
|
8
|
+
def nested_form_attached_field?(field)
|
9
|
+
field.respond_to?(:nested_form)
|
10
|
+
end
|
11
|
+
|
12
|
+
def field_label(form, field_name:)
|
13
|
+
field_name = field_name.to_s.split(".").first.to_sym
|
14
|
+
|
15
|
+
form.fields.select do |field|
|
16
|
+
field.name == field_name
|
17
|
+
end.first&.label
|
18
|
+
end
|
19
|
+
|
20
|
+
def fields_path
|
21
|
+
form = @field.form
|
22
|
+
|
23
|
+
case form
|
24
|
+
when Form
|
25
|
+
form_fields_path(form)
|
26
|
+
when NestedForm
|
27
|
+
nested_form_fields_path(form)
|
28
|
+
else
|
29
|
+
raise "Unknown form: #{form.class}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|