Module: G5ComponentGarden
- Defined in:
- lib/g5_component_garden.rb,
lib/g5_component_garden/engine.rb,
lib/g5_component_garden/version.rb
Defined Under Namespace
Classes: Engine
Constant Summary collapse
- COMPONENT_PATH =
"public/static/components/"
- VERSION =
"0.2.1"
Class Method Summary collapse
- .all ⇒ Object
- .assemble_component_assets(component, directory) ⇒ Object
- .edit_path(directory) ⇒ Object
- .file_basenames(*path) ⇒ Object
- .file_paths(*path) ⇒ Object
- .file_paths_without_public(*path) ⇒ Object
- .find(slug) ⇒ Object
- .get_directory(directory) ⇒ Object
- .get_html(file) ⇒ Object
- .merge_edit_and_show_markup(directory) ⇒ Object
- .parse_from_directory(directory) ⇒ Object
- .show_path(directory) ⇒ Object
Class Method Details
.all ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/g5_component_garden.rb', line 10 def all # each directory in public/components is a component components = file_paths(COMPONENT_PATH, "*") # parse from directory each one and return them as an Array components.map do |component_directory| parse_from_directory(component_directory) end end |
.assemble_component_assets(component, directory) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/g5_component_garden.rb', line 55 def assemble_component_assets(component, directory) component_assets = file_basenames(directory, "*").select{ |f| ['stylesheets', 'images', 'javascripts'].include?(f) } component_assets.each do |component_asset| folder = component_asset.singularize file_paths_without_public(directory, component_asset, "*").each do |file| component.add_property("u-g5-#{folder}", file) end end component end |
.edit_path(directory) ⇒ Object
47 48 49 |
# File 'lib/g5_component_garden.rb', line 47 def edit_path(directory) "#{directory}/edit.html" end |
.file_basenames(*path) ⇒ Object
66 67 68 |
# File 'lib/g5_component_garden.rb', line 66 def file_basenames(*path) Dir[File.join(path)].map { |d| File.basename(d) } end |
.file_paths(*path) ⇒ Object
70 71 72 |
# File 'lib/g5_component_garden.rb', line 70 def file_paths(*path) Dir[File.join(path)].map { |d| File.path(d) } end |
.file_paths_without_public(*path) ⇒ Object
74 75 76 |
# File 'lib/g5_component_garden.rb', line 74 def file_paths_without_public(*path) Dir[File.join(path)].map { |d| File.path(d).split("/")[1..-1].join("/") } end |
.find(slug) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/g5_component_garden.rb', line 19 def find(slug) # look for directory in public/components with name slug component = file_paths(COMPONENT_PATH, slug).first # parse from directory parse_from_directory(component) end |
.get_directory(directory) ⇒ Object
78 79 80 |
# File 'lib/g5_component_garden.rb', line 78 def get_directory(directory) directory.split("/")[1..-1].join("/") end |
.get_html(file) ⇒ Object
99 100 101 |
# File 'lib/g5_component_garden.rb', line 99 def get_html(file) open(file).read end |
.merge_edit_and_show_markup(directory) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/g5_component_garden.rb', line 82 def merge_edit_and_show_markup(directory) markup = "" markup << %{ <!-- BEGIN EDIT FORM MARKUP --> #{get_html(edit_path(directory))} <!-- END EDIT FORM MARKUP --> } if File.exist?(edit_path(directory)) markup << %{ <!-- BEGIN SHOW MARKUP --> #{get_html(show_path(directory))} <!-- END SHOW MARKUP --> } if File.exist?(show_path(directory)) markup end |
.parse_from_directory(directory) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/g5_component_garden.rb', line 26 def parse_from_directory(directory) # assign name, summary, and preview from index.html component = Microformats2.parse(File.join(directory, "index.html")).g5_components.first relative_directory = get_directory(directory) # assign uid as slug from directory name for now uid = directory.split("/").last component.add_property("u-g5-uid", uid) thumbnail_path = "#{relative_directory}/images/thumbnail.png" component.add_property("u-photo", thumbnail_path) component.add_property("u-g5-edit_template", edit_path(relative_directory)) component.add_property("u-g5-show_template", show_path(relative_directory)) e_content = merge_edit_and_show_markup(directory) component.add_property("e-content", e_content) assemble_component_assets(component, directory) end |
.show_path(directory) ⇒ Object
51 52 53 |
# File 'lib/g5_component_garden.rb', line 51 def show_path(directory) "#{directory}/show.html" end |