Class: Alephant::Preview::Template
- Inherits:
-
Object
- Object
- Alephant::Preview::Template
- Defined in:
- lib/alephant/preview/template.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply_static_host_regex_to(string) ⇒ Object
- #host ⇒ Object
- #path ⇒ Object
- #static_host_regex ⇒ Object
- #template ⇒ Object
- #update(template_location) ⇒ Object
- #uri ⇒ Object
Class Method Details
.update(template_location) ⇒ Object
8 9 10 |
# File 'lib/alephant/preview/template.rb', line 8 def self.update(template_location) self.new.update(template_location) end |
Instance Method Details
#apply_static_host_regex_to(string) ⇒ Object
42 43 44 |
# File 'lib/alephant/preview/template.rb', line 42 def apply_static_host_regex_to(string) string.gsub(static_host_regex, '{{{static_host}}}') end |
#host ⇒ Object
25 26 27 |
# File 'lib/alephant/preview/template.rb', line 25 def host "#{uri.scheme}://#{uri.host}" end |
#path ⇒ Object
29 30 31 |
# File 'lib/alephant/preview/template.rb', line 29 def path uri.path end |
#static_host_regex ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/alephant/preview/template.rb', line 46 def static_host_regex return @static_host_regex if not @static_host_regex.nil? static_host_regex_from_env = ENV['STATIC_HOST_REGEX'] raise Exception.new("STATIC_HOST_REGEX is unset!") if static_host_regex_from_env.nil? @static_host_regex = Regexp.new(static_host_regex_from_env) end |
#template ⇒ Object
12 13 14 15 16 17 |
# File 'lib/alephant/preview/template.rb', line 12 def template response = Faraday.new(:url => host).get(path) raise "Can't get template" if response.status != 200 apply_static_host_regex_to response.body end |
#update(template_location) ⇒ Object
19 20 21 22 23 |
# File 'lib/alephant/preview/template.rb', line 19 def update(template_location) File.open(template_location, 'w') { |file| file.write(template) } end |
#uri ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/alephant/preview/template.rb', line 33 def uri return @uri if not @uri.nil? uri_from_env = ENV['PREVIEW_TEMPLATE_URL'] raise Exception.new("PREVIEW_TEMPLATE_URL is unset!") if uri_from_env.nil? @uri = URI(uri_from_env) end |