Class: Crystal::Plugin::Web
- Inherits:
-
Object
- Object
- Crystal::Plugin::Web
- Defined in:
- lib/crystal_ext/plugin/web.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
Instance Method Summary collapse
- #asset(name) ⇒ Object
- #autoload(*list) ⇒ Object
-
#initialize(dir) ⇒ Web
constructor
A new instance of Web.
- #locales ⇒ Object
- #require_paths(*relative_paths) ⇒ Object
- #routes ⇒ Object
Constructor Details
#initialize(dir) ⇒ Web
Returns a new instance of Web.
6 7 8 |
# File 'lib/crystal_ext/plugin/web.rb', line 6 def initialize dir @dir = dir end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
4 5 6 |
# File 'lib/crystal_ext/plugin/web.rb', line 4 def dir @dir end |
Instance Method Details
#asset(name) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/crystal_ext/plugin/web.rb', line 10 def asset name require 'asset_packager' AssetPackager.add "#{dir}/config/asset_packages.yml", "#{dir}/public" crystal.after :environment do crystal.ensure_public_symlink name, "#{dir}/public" end end |
#autoload(*list) ⇒ Object
38 39 40 41 |
# File 'lib/crystal_ext/plugin/web.rb', line 38 def autoload *list list = list.first if list.first.is_a? Array list.each{|d| autoload_dir "#{dir}/#{d}", true} end |
#locales ⇒ Object
26 27 28 |
# File 'lib/crystal_ext/plugin/web.rb', line 26 def locales I18n.load_path += Dir["#{dir}/config/locales/**/*.{rb,yml}"] end |
#require_paths(*relative_paths) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/crystal_ext/plugin/web.rb', line 30 def require_paths *relative_paths relative_paths = relative_paths.first if relative_paths.first.is_a? Array relative_paths.each do |relative_path| path = "#{dir}/#{relative_path}" $LOAD_PATH << path unless $LOAD_PATH.include? path end end |
#routes ⇒ Object
19 20 21 22 23 24 |
# File 'lib/crystal_ext/plugin/web.rb', line 19 def routes crystal.after :environment do routes_file = "#{dir}/config/routes.rb" load routes_file if File.exist? routes_file end end |