Module: CreateGeocitiesApp
- Defined in:
- lib/create_geocities_app/themes.rb,
lib/create_geocities_app/version.rb,
lib/create_geocities_app/generator.rb
Constant Summary collapse
- THEMES =
{ "neon" => { bg: "#000000", bg_pattern: "radial-gradient(circle, #001100 1px, transparent 1px)", bg_size: "20px 20px", text_color: "#00FF00", heading_color: "#FFFF00", link_color: "#FF00FF", link_hover: "#00FFFF", accent_color: "#00FFFF", border_light: "#00FF00", border_dark: "#003300", panel_bg: "#001100", panel_border: "#00FF00", counter_bg: "#000000", counter_text: "#00FF00", table_border: "#00FF00", table_header_bg: "#003300", glow_color: "#00FF00", nav_active_bg: "#00FF00", nav_active_text: "#000000", name: "Neon", }, "space" => { bg: "#000033", bg_pattern: "radial-gradient(circle, #ffffff 1px, transparent 1px)", bg_size: "30px 30px", text_color: "#CCCCFF", heading_color: "#FFDD00", link_color: "#00FFFF", link_hover: "#FF6600", accent_color: "#FF6600", border_light: "#6666FF", border_dark: "#000022", panel_bg: "#000055", panel_border: "#6666FF", counter_bg: "#000022", counter_text: "#00FFFF", table_border: "#6666FF", table_header_bg: "#000055", glow_color: "#6666FF", nav_active_bg: "#FFDD00", nav_active_text: "#000033", name: "Space", }, "candy" => { bg: "#FF69B4", bg_pattern: "repeating-linear-gradient(45deg, #FF1493 0px, #FF1493 2px, #FF69B4 2px, #FF69B4 20px)", bg_size: "auto", text_color: "#FFFFFF", heading_color: "#FFFF00", link_color: "#00FFFF", link_hover: "#FF1493", accent_color: "#FF1493", border_light: "#FFFFFF", border_dark: "#CC0066", panel_bg: "#FF1493", panel_border: "#FFFFFF", counter_bg: "#CC0066", counter_text: "#FFFF00", table_border: "#FFFFFF", table_header_bg: "#FF1493", glow_color: "#FFFFFF", nav_active_bg: "#FFFF00", nav_active_text: "#CC0066", name: "Candy", }, "forest" => { bg: "#003300", bg_pattern: "repeating-linear-gradient(0deg, #002200 0px, #002200 1px, #003300 1px, #003300 20px)", bg_size: "auto", text_color: "#CCFFCC", heading_color: "#FFDD00", link_color: "#99FF99", link_hover: "#FF6600", accent_color: "#FF6600", border_light: "#66FF66", border_dark: "#001100", panel_bg: "#002200", panel_border: "#66FF66", counter_bg: "#001100", counter_text: "#99FF99", table_border: "#66FF66", table_header_bg: "#002200", glow_color: "#66FF66", nav_active_bg: "#FFDD00", nav_active_text: "#002200", name: "Forest", }, "windows" => { bg: "#008080", bg_pattern: "none", bg_size: "auto", text_color: "#000000", heading_color: "#000080", link_color: "#000080", link_hover: "#FF0000", accent_color: "#000080", border_light: "#FFFFFF", border_dark: "#808080", panel_bg: "#C0C0C0", panel_border: "#808080", counter_bg: "#000080", counter_text: "#FFFFFF", table_border: "#808080", table_header_bg: "#000080", glow_color: "#000080", nav_active_bg: "#000080", nav_active_text: "#FFFFFF", name: "Windows 95", }, }.freeze
- VERSION =
"1.0.1"- ALL_PAGES =
[ { key: "index", label: "🏠 Home", file: "index.html" }, { key: "about", label: "👤 About Me", file: "about.html" }, { key: "gallery", label: "🖼️ Gallery", file: "gallery.html" }, { key: "guestbook", label: "📖 Guestbook", file: "guestbook.html" }, { key: "links", label: "🔗 Cool Links", file: "links.html" }, ].freeze
- TEMPLATE_DIR =
File.("../../../templates", __FILE__)
Class Method Summary collapse
- .build_nav_links(pages, current_page) ⇒ Object
- .generate(output_dir, answers) ⇒ Object
- .get_theme(name) ⇒ Object
- .interpolate(template, vars) ⇒ Object
Class Method Details
.build_nav_links(pages, current_page) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/create_geocities_app/generator.rb', line 19 def self.build_nav_links(pages, current_page) active = ["index"] + pages ALL_PAGES.select { |p| active.include?(p[:key]) }.map do |p| cls = p[:key] == current_page ? "nav-link nav-active" : "nav-link" %(<a href="#{p[:file]}" class="#{cls}">#{p[:label]}</a>) end.join("\n ") end |
.generate(output_dir, answers) ⇒ Object
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 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/create_geocities_app/generator.rb', line 27 def self.generate(output_dir, answers) theme = get_theme(answers[:theme]) pages = answers[:pages] || [] FileUtils.mkdir_p(File.join(output_dir, "css")) FileUtils.mkdir_p(File.join(output_dir, "js")) base_vars = { "SITE_NAME" => answers[:site_name], "AUTHOR_NAME" => answers[:author_name], "THEME_NAME" => theme[:name], "BG" => theme[:bg], "BG_PATTERN" => theme[:bg_pattern], "BG_SIZE" => theme[:bg_size], "TEXT_COLOR" => theme[:text_color], "HEADING_COLOR" => theme[:heading_color], "LINK_COLOR" => theme[:link_color], "LINK_HOVER" => theme[:link_hover], "ACCENT_COLOR" => theme[:accent_color], "BORDER_LIGHT" => theme[:border_light], "BORDER_DARK" => theme[:border_dark], "PANEL_BG" => theme[:panel_bg], "PANEL_BORDER" => theme[:panel_border], "COUNTER_BG" => theme[:counter_bg], "COUNTER_TEXT" => theme[:counter_text], "TABLE_BORDER" => theme[:table_border], "TABLE_HEADER_BG" => theme[:table_header_bg], "GLOW_COLOR" => theme[:glow_color], "NAV_ACTIVE_BG" => theme[:nav_active_bg], "NAV_ACTIVE_TEXT" => theme[:nav_active_text], "CURSOR_EFFECT" => answers[:cursor_effect] || "none", "FALLING_EFFECT" => answers[:falling_effect] || "none", "WELCOME_ALERT" => answers[:welcome_alert] ? "true" : "false", "PLAY_MUSIC" => answers[:play_music] ? "true" : "false", "FAKE_HIGH_COUNT" => answers[:fake_high_count] ? "true" : "false", "YEAR" => Time.now.year.to_s, } css_src = File.read(File.join(TEMPLATE_DIR, "css", "style.css")) File.write(File.join(output_dir, "css", "style.css"), interpolate(css_src, base_vars)) js_src = File.read(File.join(TEMPLATE_DIR, "js", "main.js")) File.write(File.join(output_dir, "js", "main.js"), interpolate(js_src, base_vars)) pages_to_generate = [{ key: "index", file: "index.html" }] + pages.map { |p| { key: p, file: "#{p}.html" } } generated = [] pages_to_generate.each do |page| tmpl = File.join(TEMPLATE_DIR, page[:file]) next unless File.exist?(tmpl) nav = build_nav_links(pages, page[:key]) html = interpolate(File.read(tmpl), base_vars.merge("NAV_LINKS" => nav)) File.write(File.join(output_dir, page[:file]), html) generated << page[:file] end generated end |
.get_theme(name) ⇒ Object
50 51 52 |
# File 'lib/create_geocities_app/themes.rb', line 50 def self.get_theme(name) THEMES[name] || THEMES["neon"] end |
.interpolate(template, vars) ⇒ Object
15 16 17 |
# File 'lib/create_geocities_app/generator.rb', line 15 def self.interpolate(template, vars) template.gsub(/\{\{(\w+)\}\}/) { vars[$1] || vars[$1.to_sym] || "{{#{$1}}}" }.to_s end |