Module: Themeable::Theme
- Defined in:
- lib/themeable/theme.rb
Overview
Theme’s basic module, automatically define methods
- theme_name
- root_path
- theme_path
Class Method Summary collapse
Class Method Details
.included(subclass) ⇒ Object
8 9 10 11 12 13 14 15 16 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 64 65 66 67 68 69 70 71 72 |
# File 'lib/themeable/theme.rb', line 8 def self.included(subclass) Themeable.add_theme(subclass) # set default values caller_file = caller.first if caller_file =~ %r{/theme_(.+?)/lib/theme_\1\.rb} default_theme_name = $1.to_sym default_root = File.(File.join(caller_file, '../../')) end subclass.instance_eval " @theme_name = \#{default_theme_name.inspect}\n\n # Theme name\n #\n # @return [Symbol]\n def theme_name\n @theme_name || raise(\"Theme name is no defined\")\n end\n\n @root_path = \#{default_root.inspect}\n\n # Theme project's root path\n #\n # @return [String]\n def root_path\n @root_path || raise(\"Theme project's root path is no defined\")\n end\n\n # Theme's relative path, 'theme' by default\n #\n # @return [String] default is 'theme'\n def theme_path\n @theme_path || 'theme'\n end\n\n protected\n\n # Set theme name\n #\n # @param [String, Symbol] theme_name\n # @return [Symbol] symbolized theme_name\n def set_theme_name(theme_name)\n @theme_name = theme_name.to_sym\n end\n\n # Set root path of theme project\n #\n # @param [String] path\n # @return [String]\n def set_root_path(path)\n @root_path = path\n end\n\n # Set theme's relative path, which path includes assets and views\n #\n # @param [String] path is a relative path where assets and views locate.\n # @return [String]\n def set_theme_path(path)\n @theme_path = theme_path\n end\n\n RUBY\nend\n", __FILE__, __LINE__ + 1 |