Class: Recipes::VueAdmin
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Recipes::VueAdmin
- Defined in:
- lib/potassium/recipes/vue_admin.rb
Instance Method Summary collapse
- #active_admin_js ⇒ Object
- #add_component_integration ⇒ Object
- #add_vue_admin ⇒ Object
- #add_vue_component_library ⇒ Object
- #ask ⇒ Object
- #component_builder ⇒ Object
- #create ⇒ Object
- #install ⇒ Object
- #installed? ⇒ Boolean
- #vue_component ⇒ Object
Instance Method Details
#active_admin_js ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/potassium/recipes/vue_admin.rb', line 128 def active_admin_js " import { createApp } from 'vue';\n import AdminComponent from './components/admin-component.vue';\n\n function onLoad() {\n if (document.getElementById('wrapper') !== null) {\n const app = createApp({\n mounted() {\n // We need to re-trigger DOMContentLoaded for ArcticAdmin after Vue replaces DOM elements\n window.document.dispatchEvent(new Event('DOMContentLoaded', {\n bubbles: true,\n cancelable: true,\n }));\n },\n });\n app.component('AdminComponent', AdminComponent);\n app.mount('#wrapper');\n }\n\n return null;\n }\n\n document.addEventListener('DOMContentLoaded', onLoad, { once: true });\n HERE\nend\n" |
#add_component_integration ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/potassium/recipes/vue_admin.rb', line 52 def add_component_integration line = "class CustomFooter < ActiveAdmin::Component" initializer = "config/initializers/active_admin.rb" gsub_file initializer, /(#{Regexp.escape(line)})/mi do |_match| " require \"vue_component.rb\"\n AUTO_BUILD_ELEMENTS=[:admin_component, :template, :slot]\n component_creator(AUTO_BUILD_ELEMENTS)\n\n \#{line}\n HERE\n end\nend\n" |
#add_vue_admin ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/potassium/recipes/vue_admin.rb', line 35 def add_vue_admin add_vue_component_library add_component_integration js_line = 'import "activeadmin_addons"' gsub_file( 'app/javascript/active_admin.js', js_line, " \#{js_line}\n \#{active_admin_js}\n HERE\n )\n copy_file '../assets/active_admin/admin-component.vue',\n 'app/javascript/components/admin-component.vue',\n force: true\nend\n" |
#add_vue_component_library ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/potassium/recipes/vue_admin.rb', line 66 def add_vue_component_library lib_component_path = "lib/vue_component.rb" class_definitions = " \#{vue_component}\n \#{component_builder}\n HERE\n File.open(lib_component_path, \"w\") { |file| file.write(class_definitions) }\nend\n" |
#ask ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/potassium/recipes/vue_admin.rb', line 2 def ask if selected?(:admin_mode) vue_admin = answer(:vue_admin) do Ask.confirm "Do you want Vue support for ActiveAdmin?" end set(:vue_admin, vue_admin) set(:front_end, :vue) if vue_admin end end |
#component_builder ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/potassium/recipes/vue_admin.rb', line 110 def component_builder " def component_creator(auto_build_elements)\n auto_build_elements.each do |element|\n as_string=element.to_s\n camelized_element = as_string.camelize\n Object.const_set(camelized_element,Class.new(VueComponent))\n Object.const_get(camelized_element).class_eval do\n builder_method as_string.to_sym\n def tag_name\n self.class.to_s.underscore\n end\n end\n end\n end\n HERE\nend\n" |
#create ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/potassium/recipes/vue_admin.rb', line 12 def create recipe = self if selected?(:vue_admin) after(:admin_install) do recipe.add_vue_admin end end end |
#install ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/potassium/recipes/vue_admin.rb', line 21 def install active_admin = load_recipe(:admin) if active_admin.installed? add_vue_admin info "VueAdmin installed" else info "VueAdmin can't be installed because Active Admin isn't installed." end end |
#installed? ⇒ Boolean
31 32 33 |
# File 'lib/potassium/recipes/vue_admin.rb', line 31 def installed? dir_exist?("app/assets/javascripts/admin") end |
#vue_component ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/potassium/recipes/vue_admin.rb', line 76 def vue_component " class VueComponent < Arbre::Component\n builder_method :root\n def tag_name\n :root\n end\n\n def initialize(*)\n super\n end\n\n def build(attributes = {})\n super(process_attributes(attributes))\n end\n\n def process_attributes(attributes)\n vue_attributes = {}\n attributes.each do |key, value|\n dasherized_key = key.to_s.dasherize\n if value.is_a?(String)\n vue_attributes[dasherized_key] = value\n elsif !dasherized_key.index(':').nil? && dasherized_key.index(':').zero?\n vue_attributes[dasherized_key] = value.to_json\n else\n vue_attributes[\":\" + dasherized_key] = value.to_json\n end\n end\n vue_attributes\n end\n end\n HERE\nend\n" |