Class: Hobby::Pages
Defined Under Namespace
Classes: Directory
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #css ⇒ Object
- #css_tag ⇒ Object
-
#initialize(directory) ⇒ Pages
constructor
A new instance of Pages.
- #js_at_name(name) ⇒ Object
- #js_tag ⇒ Object
- #not_found ⇒ Object
Constructor Details
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
14 15 16 |
# File 'lib/hobby/pages.rb', line 14 def directory @directory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/hobby/pages.rb', line 14 def name @name end |
Instance Method Details
#css ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/hobby/pages.rb', line 64 def css style_file = "#{directory}/css/pages/#{name}.sass" if File.exist? style_file sass_string = IO.read style_file load_path = "#{directory}/css/pages/#{name}" Sass::Engine.new(sass_string, load_paths: [load_path]).render end end |
#css_tag ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/hobby/pages.rb', line 56 def css_tag @css_tag ||= if css "<style>#{css}</style>" else '' end end |
#js_at_name(name) ⇒ Object
81 82 83 |
# File 'lib/hobby/pages.rb', line 81 def js_at_name name directory.sprockets["pages/#{name}.js"] end |
#js_tag ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/hobby/pages.rb', line 73 def js_tag @js_tag ||= if js_at_name(name) "<script src='#{env['SCRIPT_NAME']}/#{name}.js'></script>" else '' end end |
#not_found ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hobby/pages.rb', line 44 def not_found response.status = 404 name, @name = @name, '404' if page = @directory[@name] page.render self else "404. The page named '#{name}' was not found." end end |