Skip to content

Commit

Permalink
complete the setting type generator
Browse files Browse the repository at this point in the history
  • Loading branch information
did committed Nov 12, 2024
1 parent a7ef19b commit 4718e92
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/models/maglev/setting_type_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def types
end

def register(id:, klass: nil)
klass ||= "Maglev::SettingTypes::#{id.camelize}".constantize
klass ||= "Maglev::SettingTypes::#{id.to_s.camelize}".constantize
@setting_types[id.to_sym] = klass.new
end

Expand Down
21 changes: 18 additions & 3 deletions lib/generators/maglev/setting_type_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class SettingTypeGenerator < Rails::Generators::NamedBase

def plugin_name
(@plugin_name ||= options[:plugin]).tap do
raise 'Missing plugin option' if @plugin_name.blank?
if @plugin_name.blank?
puts '🚨 You need to pass the id of a Maglev plugin'
exit 0
end
end
end

Expand All @@ -21,17 +24,29 @@ def generate
end

def register_setting_type_in_ruby
inject_into_file "packages/#{options[:plugin]}/lib/#{options[:plugin]}/engine.rb", before: / end\n^end/ do
inject_into_file "packages/#{plugin_name}/lib/#{plugin_name}/engine.rb", before: / end\n^end/ do
<<-RUBY
config.to_prepare do
Maglev.register_setting_type(id: :#{table_name})
end
RUBY
end
end

def register_setting_type_in_javascript
raise 'TODO'
prepend_to_file "packages/#{plugin_name}/index.js" do
<<-JAVASCRIPT
import { registerInput } from '@/misc/dynamic-inputs'
import UIKit#{class_name}Input from './app/frontend/editor/components/kit/#{table_name}-input.vue'
JAVASCRIPT
end

inject_into_file "packages/#{plugin_name}/index.js", before: /^}/ do
<<-JAVASCRIPT
registerInput('#{table_name}', UIKit#{class_name}Input, (props, _options) => props)
JAVASCRIPT
end
end

private
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# rubocop:disable Style/ClassAndModuleChildren
class Maglev:SettingTypes::<%= class_name %> < Maglev::SettingTypes::Base
class Maglev::SettingTypes::<%= class_name %> < Maglev::SettingTypes::Base
# def cast_value(value)
# value
# end
Expand Down

0 comments on commit 4718e92

Please sign in to comment.