Class: Landable::TidyService::Result

Inherits:
Object
  • Object
show all
Defined in:
app/services/landable/tidy_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Result

Returns a new instance of Result.



117
118
119
# File 'app/services/landable/tidy_service.rb', line 117

def initialize source
  @source = source
end

Instance Method Details

#bodyObject



125
126
127
128
129
# File 'app/services/landable/tidy_service.rb', line 125

def body
  if match = @source.match(/<body(?: [^>]*)?>(.*)<\/body>/m)
    deindent match[1]
  end
end

#cssObject



137
138
139
140
141
# File 'app/services/landable/tidy_service.rb', line 137

def css
  links = head.try :scan, /<link [^>]*type=['"]text\/css['"][^>]*>/
  styles = head.try :scan, /<style[^>]*>.*?<\/style>/m
  [links.to_a, styles.to_a].flatten.join("\n\n")
end

#headObject



131
132
133
134
135
# File 'app/services/landable/tidy_service.rb', line 131

def head
  if match = @source.match(/<head>(.*)<\/head>/m)
    deindent match[1]
  end
end

#to_sObject



121
122
123
# File 'app/services/landable/tidy_service.rb', line 121

def to_s
  @source
end