admin_script 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +3 -0
  5. data/README.md +57 -0
  6. data/Rakefile +2 -0
  7. data/admin_script.gemspec +31 -0
  8. data/app/assets/javascripts/admin_script/.keep +0 -0
  9. data/app/assets/javascripts/admin_script/application.js +19 -0
  10. data/app/assets/stylesheets/admin_script/.keep +0 -0
  11. data/app/assets/stylesheets/admin_script/application.scss +3 -0
  12. data/app/controllers/.keep +0 -0
  13. data/app/controllers/admin_script/admin_scripts_controller.rb +40 -0
  14. data/app/controllers/admin_script/application_controller.rb +4 -0
  15. data/app/helpers/.keep +0 -0
  16. data/app/mailers/.keep +0 -0
  17. data/app/models/.keep +0 -0
  18. data/app/views/admin_script/admin_scripts/_default_form.html.slim +26 -0
  19. data/app/views/admin_script/admin_scripts/edit.html.slim +22 -0
  20. data/app/views/admin_script/admin_scripts/index.html.slim +15 -0
  21. data/app/views/layouts/admin_script/application.html.slim +20 -0
  22. data/config/locales/admin_script/en.yml +21 -0
  23. data/config/locales/admin_script/ja.yml +21 -0
  24. data/config/routes.rb +5 -0
  25. data/dummy/.gitignore +2 -0
  26. data/dummy/Rakefile +6 -0
  27. data/dummy/app/models/admin_script/expire_user_session.rb +27 -0
  28. data/dummy/bin/rails +4 -0
  29. data/dummy/config/application.rb +14 -0
  30. data/dummy/config/boot.rb +5 -0
  31. data/dummy/config/environment.rb +5 -0
  32. data/dummy/config/environments/development.rb +9 -0
  33. data/dummy/config/environments/test.rb +15 -0
  34. data/dummy/config/routes.rb +4 -0
  35. data/dummy/config/secrets.yml +22 -0
  36. data/dummy/config.ru +5 -0
  37. data/lib/admin_script/base.rb +84 -0
  38. data/lib/admin_script/bootstrap.rb +20 -0
  39. data/lib/admin_script/configuration.rb +32 -0
  40. data/lib/admin_script/engine.rb +40 -0
  41. data/lib/admin_script/type_attributes.rb +39 -0
  42. data/lib/admin_script/version.rb +3 -0
  43. data/lib/admin_script.rb +19 -0
  44. data/lib/generators/admin_script/controller/controller_generator.rb +21 -0
  45. data/lib/generators/admin_script/controller/templates/controller.rb +3 -0
  46. data/lib/generators/admin_script/controller/templates/layout.html.slim +21 -0
  47. data/lib/generators/admin_script/install/install_generator.rb +15 -0
  48. data/lib/generators/admin_script/install/templates/initializer.rb +14 -0
  49. data/lib/generators/admin_script/model/model_generator.rb +15 -0
  50. data/lib/generators/admin_script/model/templates/model.rb +26 -0
  51. data/lib/generators/admin_script/view/templates/view.html.slim +26 -0
  52. data/lib/generators/admin_script/view/view_generator.rb +15 -0
  53. data/lib/tasks/admin_script_tasks.rake +4 -0
  54. data/vendor/javascripts/admin_script/bootstrap-datetimepicker.min.js +2 -0
  55. data/vendor/javascripts/admin_script/jquery-2.2.4.min.js +4 -0
  56. data/vendor/javascripts/admin_script/moment-with-locales.js +12910 -0
  57. data/vendor/stylesheets/admin_script/_bootstrap-datetimepicker.scss +344 -0
  58. metadata +300 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45a05e2bb2442cfcb8f079507a2e57f34ac4d3d9
4
+ data.tar.gz: 7053298a2a820ea581ec750924f2676b2e6445c5
5
+ SHA512:
6
+ metadata.gz: 42975dd1ee0b39c165cf68cb7412b717d7b72a88ce0b142179f6f4fc298662cd6e7be1c56fe99536e1f9578b33bb8c4a97b248c178de1e712668b40cbac2ad3e
7
+ data.tar.gz: aca914a2f6fcec289192acf67dd8b6497018dcb5ca017af5185fb3b538b106cb2bf812bc3feecafb742241f1f8122b2350c68eaaaa78cd6715d6117627d7dee9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # AdminScript
2
+
3
+ A module for creating flexible, simple scripts for project in Rails.
4
+
5
+ <img width="1147" alt="edit_page_example" src="https://cloud.githubusercontent.com/assets/1688137/21744577/cd1d3bac-d55b-11e6-8a9d-bda96edd4d36.png">
6
+
7
+ ## Why use an AdminScript?
8
+
9
+ I do not want to design RESTful resource for such scripts that run only a few times a month.
10
+ A new template is also a complete waste of time.
11
+
12
+ Therefore, AdminScript provides management page of scripts.
13
+ Only once to define model to perform a script, it generates template automatically.
14
+ No configuration of routing, controller, template and as so on needed.
15
+
16
+ ## Getting Started
17
+
18
+ Add AdminScript to your Gemfile:
19
+
20
+ ```ruby
21
+ gem 'admin_script'
22
+ ```
23
+
24
+ Re-bundle, then run the installer:
25
+
26
+ ```
27
+ $ bundle exec rails generate admin_script:install
28
+ ```
29
+
30
+ AdminScript provides a rails engine that can display listing of your scripts.
31
+ Add the following to your `config/routes.rb`
32
+
33
+ ```
34
+ mount AdminScript::Engine => '/admin_scripts'
35
+ ```
36
+
37
+ ### Generators
38
+
39
+ When you have AdminScript installed
40
+
41
+ ```
42
+ bundle exec rails generate admin_script:model awesome_script
43
+ ```
44
+
45
+ ...to create the `AdminScript::AwesomeScript`.
46
+
47
+ ## Development
48
+
49
+ no doc
50
+
51
+ ## Links
52
+
53
+ - [Wiki](https://github.com/alpaca-tc/admin_script/wiki)
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alpaca-tc/admin_script.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'admin_script/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'admin_script'
7
+ spec.version = AdminScript::VERSION
8
+ spec.authors = ['alpaca-tc']
9
+ spec.email = ['alpaca-tc@alpaca.tc']
10
+ spec.licenses = ['MIT']
11
+
12
+ spec.summary = %q{A module for creating flexible, simple scripts for project in Rails.}
13
+ spec.homepage = 'https://github.com/alpaca-tc/admin_script'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rails', '>= 4.1.0', '< 6.0.0'
22
+ spec.add_dependency 'method_source', '>= 0.8.0', '< 0.10.0'
23
+ spec.add_dependency 'slim-rails', '>= 3.0.0', '< 5.0.0'
24
+ spec.add_dependency 'bootstrap-sass', '>= 3.0.0', '< 5.0.0'
25
+ spec.add_dependency 'sass-rails', '>= 3.2', '< 7.0.0'
26
+ spec.add_dependency 'jquery-rails', '>= 1.0.0', '< 6.0.0'
27
+ spec.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3'
28
+ spec.add_development_dependency 'bundler', '~> 1.13', '>= 1.13'
29
+ spec.add_development_dependency 'rake', '~> 10.0', '>= 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0', '>= 3.0.0'
31
+ end
File without changes
@@ -0,0 +1,19 @@
1
+ //= require admin_script/jquery-2.2.4.min
2
+ //= require jquery_ujs
3
+ //= require bootstrap-sprockets
4
+ //= require admin_script/moment-with-locales
5
+ //= require admin_script/bootstrap-datetimepicker.min
6
+ //= require_self
7
+
8
+ 'use strict';
9
+
10
+ $(document).on('ready page:load', function() {
11
+ $('[data-behaviour~=datepicker]').datetimepicker({
12
+ showClose: true,
13
+ format: 'YYYY/MM/DD'
14
+ });
15
+
16
+ $('[data-behaviour~=datetimepicker]').datetimepicker({
17
+ showClose: true
18
+ });
19
+ });
File without changes
@@ -0,0 +1,3 @@
1
+ @import 'bootstrap-sprockets';
2
+ @import 'bootstrap';
3
+ @import 'admin_script/bootstrap-datetimepicker';
File without changes
@@ -0,0 +1,40 @@
1
+ class ::AdminScript::AdminScriptsController < AdminScript.configuration.parent_controller.constantize
2
+ before_action :set_admin_script_class, only: [:edit, :update]
3
+
4
+ def index
5
+ @admin_scripts = AdminScript::Base.subclasses.sort_by(&:to_s).map(&:new)
6
+ end
7
+
8
+ def edit
9
+ @admin_script = @admin_script_class.new(admin_script_params)
10
+ end
11
+
12
+ def update
13
+ @admin_script = @admin_script_class.new(admin_script_params)
14
+
15
+ if @admin_script.perform
16
+ default_path = admin_script.routes.url_helpers.admin_scripts_path
17
+ location = @admin_script.location_url.presence || default_path
18
+ message = @admin_script.success_message.presence || t('admin_script.admin_scripts.update.successfully_performed')
19
+
20
+ redirect_to location, notice: message
21
+ else
22
+ message = @admin_script.failure_message.presence || t('admin_script.admin_scripts.update.failed_performing')
23
+ flash.now[:alert] = message
24
+
25
+ render :edit, status: :unprocessable_entity
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def admin_script_params
32
+ params.require(:admin_script).permit(@admin_script_class.type_attributes.keys)
33
+ rescue ActionController::ParameterMissing
34
+ nil
35
+ end
36
+
37
+ def set_admin_script_class
38
+ @admin_script_class = AdminScript::Base.find_class(params[:id])
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module AdminScript
2
+ class ApplicationController < AdminScript.configuration.parent_controller.constantize
3
+ end
4
+ end
data/app/helpers/.keep ADDED
File without changes
data/app/mailers/.keep ADDED
File without changes
data/app/models/.keep ADDED
File without changes
@@ -0,0 +1,26 @@
1
+ - f.object.class.type_attributes.each do |name, type|
2
+ .form-group
3
+ - if type == :boolean
4
+ .checkbox
5
+ = f.label name, class: 'form-label'
6
+ = f.check_box name
7
+ = name
8
+ - else
9
+ = f.label name
10
+ - case type
11
+ - when :integer, :big_integer
12
+ = f.number_field name, class: 'form-control'
13
+ - when :float, :decimal
14
+ = f.number_field name, step: 0.01, class: 'form-control'
15
+ - when :string
16
+ = f.text_field name, class: 'form-control'
17
+ - when :date
18
+ = f.text_field name, class: 'form-control', data: { behaviour: 'datepicker' }
19
+ - when :datetime
20
+ = f.text_field name, class: 'form-control', data: { behaviour: 'datetimepicker' }
21
+ - when :binary
22
+ = f.file_field name, class: 'form-control'
23
+ - when :text
24
+ = f.text_field name, class: 'form-control'
25
+ - when :time
26
+ = f.time_select name, class: 'form-control'
@@ -0,0 +1,22 @@
1
+ - content_for(:title, t('.title', id: @admin_script.to_param))
2
+ h1.page-header = yield(:title)
3
+
4
+ .panel.panel-default style='position: relative'
5
+ .panel-body
6
+ - url = AdminScript::Engine.routes.url_helpers.admin_script_path(@admin_script)
7
+ = form_for @admin_script, url: url, as: :admin_script, method: 'patch' do |f|
8
+ .form-group
9
+ = f.label :description
10
+ p = simple_format f.object.description
11
+
12
+ / Find custom template or default template
13
+ - template = @admin_script.model_name.element
14
+ - if lookup_context.exists?(template, lookup_context.prefixes, true)
15
+ = render template, f: f
16
+ - else
17
+ = render 'admin_script/admin_scripts/default_form', f: f
18
+
19
+ = f.button t('.perform'), class: 'btn btn-default', data: { confirm: t('.confirm') }
20
+
21
+ .panel-footer
22
+ pre = @admin_script.class.script
@@ -0,0 +1,15 @@
1
+ - content_for(:title, t('.title'))
2
+ h1.page-header = yield(:title)
3
+
4
+ table.table.table-hover
5
+ thead
6
+ tr
7
+ th = AdminScript::Base.model_name.human
8
+ th = AdminScript::Base.human_attribute_name(:description)
9
+ th
10
+ tbody
11
+ - @admin_scripts.each do |instance|
12
+ tr
13
+ td = instance.to_param
14
+ td = simple_format instance.description
15
+ td = link_to t('.open'), AdminScript::Engine.routes.url_helpers.edit_admin_script_path(instance), class: 'btn btn-default'
@@ -0,0 +1,20 @@
1
+ doctype html
2
+ html
3
+ head
4
+ meta charset='UTF-8'
5
+ meta name='referrer' content='no-referrer'
6
+
7
+ = stylesheet_link_tag 'admin_script/application', media: :all
8
+ = javascript_include_tag 'admin_script/application'
9
+ = csrf_meta_tags
10
+
11
+ title = [yield(:title).presence].compact.join(' | ')
12
+
13
+ body
14
+ .container
15
+ - { notice: :success, alert: :danger }.each do |key, type|
16
+ - if flash[key].present?
17
+ div class="alert alert-#{type}"
18
+ p = flash[key]
19
+
20
+ = yield
@@ -0,0 +1,21 @@
1
+ en:
2
+ activemodel:
3
+ models:
4
+ admin_script/base: AdminScript
5
+
6
+ attributes:
7
+ admin_script/base:
8
+ description: Description
9
+
10
+ admin_script:
11
+ admin_scripts:
12
+ index:
13
+ title: Listing of AdminScripts
14
+ open: Open
15
+ edit:
16
+ title: 'AdminScript - %{id}'
17
+ perform: Perform
18
+ confirm: Are you sure?
19
+ update:
20
+ successfully_performed: Successfully performed
21
+ failed_performing: Failed performing
@@ -0,0 +1,21 @@
1
+ ja:
2
+ activemodel:
3
+ models:
4
+ admin_script/base: AdminScript
5
+
6
+ attributes:
7
+ admin_script/base:
8
+ description: 詳細
9
+
10
+ admin_script:
11
+ admin_scripts:
12
+ index:
13
+ title: AdminScript一覧
14
+ open: 開く
15
+ edit:
16
+ title: 'AdminScript - %{id}'
17
+ perform: 実行
18
+ confirm: 実行してよろしいですか?
19
+ update:
20
+ successfully_performed: 実行しました
21
+ failed_performing: 実行できませんでした
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ AdminScript::Engine.routes.draw do
2
+ resources :admin_scripts, only: [:index, :edit, :update],
3
+ path: '',
4
+ controller: AdminScript.configuration.controller_path
5
+ end
data/dummy/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /log
2
+ /tmp
data/dummy/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,27 @@
1
+ module AdminScript
2
+ class ExpireUserSession < AdminScript::Base
3
+ self.description = 'Expire user session'
4
+
5
+ # Define type attribute to cast user input.
6
+ # the following defines `#id` and `#id=` as typecast method.
7
+ type_attribute :id, :integer
8
+
9
+ attr_reader :user
10
+
11
+ validates :id, :user, presence: true
12
+ before_validation :set_user
13
+
14
+ def perform
15
+ return false unless valid?
16
+ user.expire_session!
17
+
18
+ true
19
+ end
20
+
21
+ private
22
+
23
+ def set_user
24
+ @user = User.find_by(id: id) if id
25
+ end
26
+ end
27
+ end
data/dummy/bin/rails ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,14 @@
1
+ require_relative 'boot'
2
+
3
+ require 'action_controller/railtie'
4
+ require 'action_mailer/railtie'
5
+ require 'sprockets/railtie'
6
+
7
+ Bundler.require(*Rails.groups)
8
+ require 'admin_script'
9
+
10
+ module Dummy
11
+ class Application < Rails::Application
12
+ end
13
+ end
14
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,9 @@
1
+ Rails.application.configure do
2
+ config.cache_classes = false
3
+ config.eager_load = false
4
+ config.consider_all_requests_local = true
5
+ config.action_controller.perform_caching = false
6
+ config.active_support.deprecation = :log
7
+ config.assets.debug = true
8
+ config.assets.quiet = true
9
+ end
@@ -0,0 +1,15 @@
1
+ Rails.application.configure do
2
+ config.cache_classes = true
3
+ config.eager_load = false
4
+ config.public_file_server.enabled = true
5
+ config.public_file_server.headers = {
6
+ 'Cache-Control' => 'public, max-age=3600'
7
+ }
8
+ config.consider_all_requests_local = true
9
+ config.action_controller.perform_caching = false
10
+ config.action_dispatch.show_exceptions = false
11
+ config.action_controller.allow_forgery_protection = false
12
+ config.action_mailer.perform_caching = false
13
+ config.action_mailer.delivery_method = :test
14
+ config.active_support.deprecation = :stderr
15
+ end
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ root to: redirect('/engine')
3
+ mount AdminScript::Engine => '/engine'
4
+ end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 3c85f8a36c79047c57b5114b03fdf81000e56d24018054ce13da8bbac0804ab352fea5eb54bb016b3a9dc948851282b1f77fbaf142d87fededbff18ecb7f46c1
15
+
16
+ test:
17
+ secret_key_base: 7661dae72742599ad1c835a4575ed5c81e757c99d29878cf9e51cfb19e46092480ed31482ebd46a9e612e56aa82842973633a00c950bdf6744d0152ce563e3b4
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
data/dummy/config.ru ADDED
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,84 @@
1
+ require 'active_support/core_ext/class/subclasses'
2
+ require 'active_model'
3
+ require 'method_source'
4
+
5
+ module AdminScript
6
+ class Base
7
+ include AdminScript::TypeAttributes
8
+ include ActiveModel::Model
9
+ include ActiveModel::Validations::Callbacks
10
+ extend ActiveModel::Callbacks
11
+
12
+ define_model_callbacks :initialize, only: :after
13
+
14
+ attr_accessor :location_url
15
+
16
+ class << self
17
+ RESERVED_CLASSE_NAMES = %w(
18
+ AdminScript::Base
19
+ AdminScript::Configuration
20
+ AdminScript::Engine
21
+ AdminScript::TypeAttributes
22
+ AdminScript::VERSION
23
+ ).freeze
24
+
25
+ def inherited(subclass)
26
+ if RESERVED_CLASSE_NAMES.include?(subclass.to_s)
27
+ raise ArgumentError, "Reserved class name given. #{subclass}"
28
+ end
29
+
30
+ super
31
+
32
+ subclass.class_exec do
33
+ cattr_accessor :description
34
+ cattr_accessor :type_attributes
35
+ self.type_attributes = {}
36
+ end
37
+ end
38
+
39
+ def type_attribute(name, type)
40
+ name = name.to_sym
41
+ type = type.to_sym
42
+
43
+ define_type_attribute_accessor(name, type)
44
+ type_attributes.merge!(name => type)
45
+ end
46
+
47
+ def to_param
48
+ model_name.element
49
+ end
50
+
51
+ def find_class(element)
52
+ subclasses.find { |klass| klass.to_param == element }
53
+ end
54
+
55
+ def script
56
+ instance_method(:perform).source
57
+ end
58
+ end
59
+
60
+ def initialize(*)
61
+ run_callbacks :initialize do
62
+ super
63
+ end
64
+ end
65
+
66
+ def to_param
67
+ self.class.to_param
68
+ end
69
+
70
+ def perform
71
+ raise NotImplementedError, 'not implemented yet.'
72
+ end
73
+
74
+ def failure_message; end
75
+
76
+ def success_message; end
77
+
78
+ private
79
+
80
+ def url_helpers
81
+ Rails.application.routes.url_helpers
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,20 @@
1
+ require 'sass'
2
+
3
+ module AdminScript
4
+ class Bootstrap
5
+ def load!
6
+ require 'sass'
7
+ ::Sass.load_paths << stylesheets_path
8
+ end
9
+
10
+ private
11
+
12
+ def gem_path
13
+ File.expand_path('../..', File.dirname(__FILE__))
14
+ end
15
+
16
+ def stylesheets_path
17
+ File.join(gem_path, 'vendor', 'stylesheets')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ require 'delegate'
2
+
3
+ module AdminScript
4
+ class Configuration
5
+ def self.define_configuration(name, default: nil)
6
+ define_method name do
7
+ @configurations[name]
8
+ end
9
+
10
+ define_method :"#{name}=" do |value|
11
+ @configurations[name] = value
12
+ end
13
+
14
+ default_configurations[name] = default
15
+ end
16
+
17
+ def self.default_configurations
18
+ @default_configurations ||= {}
19
+ end
20
+
21
+ def initialize
22
+ @configurations = self.class.default_configurations.clone
23
+ end
24
+
25
+ define_configuration(:admin_script_paths, default: [
26
+ (Rails.root.join('app', 'models', 'admin_script').to_s if defined?(Rails))
27
+ ])
28
+ define_configuration(:parent_controller, default: 'ActionController::Base')
29
+ define_configuration(:default_url_options, default: {})
30
+ define_configuration(:controller_path, default: 'admin_scripts')
31
+ end
32
+ end
@@ -0,0 +1,40 @@
1
+ require 'slim-rails'
2
+ require 'bootstrap-sass'
3
+ require 'jquery-rails'
4
+
5
+ module AdminScript
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace AdminScript
8
+
9
+ AdminScript::Bootstrap.new.load!
10
+
11
+ initializer 'admin_script.i18n' do |app|
12
+ array = Array.wrap(app.config.i18n.available_locales)
13
+ available_locales = array.blank? ? '*' : "{#{array.join ','}}"
14
+
15
+ locale_pattern = File.expand_path("../../../config/locales/admin_script/#{available_locales}.yml", __FILE__)
16
+ locale_files = Dir[locale_pattern]
17
+
18
+ app.config.i18n.load_path += locale_files
19
+ end
20
+
21
+ config.assets.paths += %w(stylesheets javascripts fonts).map do |path|
22
+ File.expand_path("../../../vendor/#{path}", __FILE__)
23
+ end
24
+
25
+ config.after_initialize do
26
+ AdminScript::Engine.routes.default_url_options = AdminScript.configuration.default_url_options.presence ||
27
+ Rails.application.routes.default_url_options
28
+ end
29
+
30
+ config.to_prepare do
31
+ AdminScript.configuration.admin_script_paths.each do |path|
32
+ finder = Pathname.new(path).join('**', '*.rb')
33
+
34
+ Dir[finder].each do |path|
35
+ require_dependency(path)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end