mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 05:40:42 +08:00
38 lines
645 B
Ruby
38 lines
645 B
Ruby
|
require_dependency 'oneboxer/handlebars_onebox'
|
||
|
|
||
|
module Oneboxer
|
||
|
class AppleAppOnebox < HandlebarsOnebox
|
||
|
|
||
|
matcher /^https?:\/\/itunes\.apple\.com\/.+$/
|
||
|
favicon 'apple.png'
|
||
|
|
||
|
# Don't masquerade as mobile
|
||
|
def http_params
|
||
|
{}
|
||
|
end
|
||
|
|
||
|
def template
|
||
|
template_path('simple_onebox')
|
||
|
end
|
||
|
|
||
|
def parse(data)
|
||
|
|
||
|
hp = Hpricot(data)
|
||
|
|
||
|
result = {}
|
||
|
|
||
|
m = hp.at("h1")
|
||
|
result[:title] = m.inner_text if m
|
||
|
|
||
|
m = hp.at("h4 ~ p")
|
||
|
result[:text] = m.inner_text[0..MAX_TEXT] if m
|
||
|
|
||
|
m = hp.at(".product img.artwork")
|
||
|
result[:image] = m['src'] if m
|
||
|
|
||
|
result
|
||
|
end
|
||
|
|
||
|
end
|
||
|
end
|