Class: Dedalus::PatternLibrary::Application
- Inherits:
-
Joyce::Application
- Object
- Joyce::Application
- Dedalus::PatternLibrary::Application
- Includes:
- Models
- Defined in:
- lib/dedalus/pattern_library/application.rb
Instance Method Summary collapse
- #all_library_items ⇒ Object
-
#click ⇒ Object
TODO move into joyce??.
- #create_library(module_to_search:, name:) ⇒ Object
- #find_descendants_of(klass, module_to_search) ⇒ Object
- #serialize_library(library) ⇒ Object
- #setup(module_to_search:, library_name:) ⇒ Object
- #welcome_section ⇒ Object
- #welcome_tab ⇒ Object
Instance Method Details
#all_library_items ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/dedalus/pattern_library/application.rb', line 130 def all_library_items LibraryItem.all.map do |item| { name: item.name, kind: item.kind, color: item.color, description: item.description, item_class_name: item.item_class_name, item_data: item.example_data } end end |
#click ⇒ Object
TODO move into joyce??
8 9 10 |
# File 'lib/dedalus/pattern_library/application.rb', line 8 def click view.click end |
#create_library(module_to_search:, name:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dedalus/pattern_library/application.rb', line 20 def create_library(module_to_search:, name:) library = Library.create(name: name) atom_section = library.create_library_section( name: "Atoms", icon: :atom, color: 'darkred', about: "Components that can't be split further" ) atom_classes = find_descendants_of(Dedalus::Atom, module_to_search) atom_section.build_items_from_classes(atom_classes, kind: 'atom') molecules_section = library.create_library_section( name: "Molecules", icon: :molecule, color: 'yellow', about: "Simple compounds of a few atoms" ) molecule_classes = find_descendants_of(Dedalus::Molecule, module_to_search) molecules_section.build_items_from_classes(molecule_classes, kind: 'molecule') organism_section = library.create_library_section({ name: "Organisms", icon: :paramecium, color: 'green', about: "Highly-complex assemblages of molecules" }) organism_classes = find_descendants_of(Dedalus::Organism, module_to_search) organism_section.build_items_from_classes(organism_classes, kind: 'organism') template_section = library.create_library_section({ name: "Templates", icon: :hive, color: 'blue', about: "Assembled screens with placeholders" }) template_classes = find_descendants_of(Dedalus::Template, module_to_search) template_section.build_items_from_classes(template_classes, kind: 'template') # template_section.create_library_item({ # name: "Library Template", # item_class_name: 'Dedalus::PatternLibrary::ApplicationTemplate', # description: "ui library app template", # example_data: ApplicationTemplate.example_data # }) # just manually create a view from models for now... library_data = serialize_library(library) library_view = LibraryView.create(library_data) view.library_view = library_view end |
#find_descendants_of(klass, module_to_search) ⇒ Object
16 17 18 |
# File 'lib/dedalus/pattern_library/application.rb', line 16 def find_descendants_of(klass, module_to_search) ObjectSpace.each_object(Class).select { |k| k < klass && k.name.deconstantize == module_to_search.name } end |
#serialize_library(library) ⇒ 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 109 |
# File 'lib/dedalus/pattern_library/application.rb', line 76 def serialize_library(library) { library_name: library.name, library_sections: [welcome_section] + library.library_sections.map do |section| { title: section.name, subtitle: section.about, color: section.color, items: section.library_items.map do |item| { name: item.name, kind: item.kind, color: section.color, description: item.description, item_class_name: item.item_class_name, item_data: item.example_data } end } end, library_section_tabs: [welcome_tab] + library.library_sections.map do |section| { name: section.name, icon: section.icon, description: section.about, section_color: section.color } end, library_items: all_library_items } end |
#setup(module_to_search:, library_name:) ⇒ Object
12 13 14 |
# File 'lib/dedalus/pattern_library/application.rb', line 12 def setup(module_to_search:, library_name:) create_library(name: library_name, module_to_search: module_to_search) end |
#welcome_section ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/dedalus/pattern_library/application.rb', line 120 def welcome_section { title: "Welcome", subtitle: "About the Dedalus library", color: 'darkgray', show_table: true, items: all_library_items } end |
#welcome_tab ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/dedalus/pattern_library/application.rb', line 111 def welcome_tab { name: "Welcome", icon: :house, description: "About the Library", section_color: "darkgray" } end |