Class: Scriptorium::Theme
- Inherits:
-
Object
- Object
- Scriptorium::Theme
- Includes:
- Contract, Exceptions, Helpers
- Defined in:
- lib/scriptorium/theme.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .copy_gem_assets_to_library(root) ⇒ Object
- .copy_gem_assets_to_theme(theme_dir) ⇒ Object
- .create_standard(root) ⇒ Object
Instance Method Summary collapse
-
#define_invariants ⇒ Object
Invariants.
- #file(portion) ⇒ Object
-
#initialize(root, name) ⇒ Theme
constructor
A new instance of Theme.
Methods included from Helpers
cf_time, change_config, clean_slugify, copy_gem_asset_to_user, copy_to_clipboard, d4, escape_html, generate_missing_asset_svg, get_asset_path, get_from_clipboard, getvars, list_gem_assets, make_dir, make_tree, need, read_commented_file, read_file, see, see_file, slugify, substitute, system!, view_dir, write_file, write_file!, ymdhms
Methods included from Exceptions
Methods included from Contract
assume, check_invariants, enabled?, invariant, verify
Constructor Details
#initialize(root, name) ⇒ Theme
Returns a new instance of Theme.
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/scriptorium/theme.rb', line 166 def initialize(root, name) assume { root.is_a?(String) && !root.empty? } assume { name.is_a?(String) && !name.empty? } @root = root @name = name define_invariants verify { @root == root } verify { @name == name } check_invariants end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/scriptorium/theme.rb', line 9 def name @name end |
Class Method Details
.copy_gem_assets_to_library(root) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/scriptorium/theme.rb', line 117 def self.copy_gem_assets_to_library(root) # Try to find gem assets and copy application-wide assets to the library begin gem_spec = Gem.loaded_specs['scriptorium'] if gem_spec gem_assets_dir = "#{gem_spec.full_gem_path}/assets" else # Development environment - use the working path gem_assets_dir = File.("assets") end if Dir.exist?(gem_assets_dir) # Copy application-wide assets to library directory library_dir = root/"assets"/"library" FileUtils.mkdir_p(library_dir) unless Dir.exist?(library_dir) # Copy sample assets (application-wide) samples_gem_dir = "#{gem_assets_dir}/samples" if Dir.exist?(samples_gem_dir) FileUtils.cp_r("#{samples_gem_dir}/.", library_dir) end end rescue => e # If gem lookup fails, continue without copying gem assets # This is expected in development/testing environments end end |
.copy_gem_assets_to_theme(theme_dir) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 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 110 111 112 113 114 115 |
# File 'lib/scriptorium/theme.rb', line 65 def self.copy_gem_assets_to_theme(theme_dir) # Try to find gem assets and copy only theme-specific assets to the theme begin gem_spec = Gem.loaded_specs['scriptorium'] if gem_spec gem_assets_dir = "#{gem_spec.full_gem_path}/assets" else # Development environment - use the working path gem_assets_dir = File.("assets") end if Dir.exist?(gem_assets_dir) # Copy only theme-specific assets to theme assets directory theme_assets_dir = theme_dir/"assets" FileUtils.mkdir_p(theme_assets_dir) unless Dir.exist?(theme_assets_dir) # Copy theme-specific assets (themes/ directory) theme_gem_dir = "#{gem_assets_dir}/themes" if Dir.exist?(theme_gem_dir) FileUtils.cp_r("#{theme_gem_dir}/.", theme_assets_dir) end # Copy theme-specific icons (icons/ui/ and icons/social/ - these could be theme-specific) icons_gem_dir = "#{gem_assets_dir}/icons" if Dir.exist?(icons_gem_dir) # Create icons directory in theme assets theme_icons_dir = theme_assets_dir/"icons" FileUtils.mkdir_p(theme_icons_dir) # Copy UI icons (could be theme-specific) ui_icons_dir = "#{icons_gem_dir}/ui" if Dir.exist?(ui_icons_dir) theme_ui_dir = theme_icons_dir/"ui" FileUtils.mkdir_p(theme_ui_dir) FileUtils.cp_r("#{ui_icons_dir}/.", theme_ui_dir) end # Copy social icons (could be theme-specific) = "#{icons_gem_dir}/social" if Dir.exist?() = theme_icons_dir/"social" FileUtils.mkdir_p() FileUtils.cp_r("#{}/.", ) end end end rescue => e # If gem lookup fails, continue without copying gem assets # This is expected in development/testing environments end end |
.create_standard(root) ⇒ Object
17 18 19 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 |
# File 'lib/scriptorium/theme.rb', line 17 def self.create_standard(root) assume { root.is_a?(String) && !root.empty? } make_tree(root/:themes, <<~EOS) standard/ ├── README.txt ├── assets/ ├── config.txt ├── header/ ├── initial/ │ └── post.lt3 ├── layout/ │ ├── config/ │ │ ├── footer.txt │ │ ├── header.txt │ │ ├── left.txt │ │ ├── main.txt │ │ └── right.txt │ ├── gen/ │ │ └── text.css │ └── layout.txt └── templates/ ├── index.lt3 ├── post.lt3 ├── index_entry.lt3 └── widget.lt3 EOS write_file("/tmp/ttree.txt", `tree`) predef = Scriptorium::StandardFiles.new std = root/:themes/:standard write_file(std/:initial/"post.lt3", predef.initial_post(:raw)) write_file(std/:templates/"post.lt3", predef.post_template("standard")) write_file(std/:templates/"index_entry.lt3", predef.index_entry) layout_text = std/:layout/"layout.txt" write_file(layout_text, predef.layout_text) config, gen = std/:layout/:config, std/:layout/:gen write_file(config/"header.txt", predef.theme_header) write_file(config/"footer.txt", predef.) write_file(config/"left.txt", predef.theme_left) write_file(config/"right.txt", predef.theme_right) write_file(config/"main.txt", predef.theme_main) # Copy gem assets to standard theme copy_gem_assets_to_theme(std) verify { Dir.exist?(root/:themes/"standard") } end |
Instance Method Details
#define_invariants ⇒ Object
Invariants
12 13 14 15 |
# File 'lib/scriptorium/theme.rb', line 12 def define_invariants invariant { @root.is_a?(String) && !@root.empty? } invariant { @name.is_a?(String) && !@name.empty? } end |
#file(portion) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/scriptorium/theme.rb', line 145 def file(portion) check_invariants assume { portion.is_a?(String) && !portion.empty? } paths = Find.find(@root/:themes/name) found = paths.find_all {|x| x.include?(portion) } case when found.size == 1 result = found[0] verify { result.is_a?(String) && File.exist?(result) } check_invariants return result when found.size > 1 # puts "Search for #{portion} found" # found.each {|x| puts " #{x}"} raise MoreThanOneResult(portion) else raise ThemeFileNotFound(portion) end end |