Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
How do I verify support for app blocks in Ruby?

In this guide: https://shopify.dev/apps/online-store/verify-support there is a Node.js example. Is there anywhere a Ruby example that does the same thing?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Ok, I did it myself:

themes = ShopifyAPI::Theme.all
publishedTheme = themes.find {|t| t.role == 'main'}
assets = ShopifyAPI::Asset.find(:all, params: {theme_id: publishedTheme.id})
APP_BLOCK_TEMPLATES = ['product', 'collection', 'index']
templateJSONFiles = assets.filter {|file| APP_BLOCK_TEMPLATES.any? {|t| file.key == "templates/#{t}.json"}}
if templateJSONFiles.size === APP_BLOCK_TEMPLATES.size
  puts 'All desired templates support sections everywhere!'
elsif templateJSONFiles.size > 0 
  puts 'Only some of the desired templates support sections everywhere.'
end

templateMainSections = templateJSONFiles.map do |tmp|
    a = ShopifyAPI::Asset.find(tmp.key, params: {theme_id: publishedTheme.id})
    json = JSON.parse(a.value)
    
    main = json['sections'].find {|k, v| k == 'main' || v['type'].start_with?('main-')}
    if main
        assets.find {|file| file.key == "sections/#{main[1]['type']}.liquid"}
    else
        nil
    end
end.compact

sectionsWithAppBlock = templateMainSections.map do |file|
    acceptsAppBlock = false
    asset = ShopifyAPI::Asset.find(file.key, params: {theme_id: publishedTheme.id})
    match = asset.value.match(/\{\%\s+schema\s+\%\}([\s\S]*?)\{\%\s+endschema\s+\%\}/m)
    schema = JSON.parse(match[1]);
    if (schema && schema['blocks']) 
        acceptsAppBlock = schema['blocks'].any? {|b| b['type'] == '@app'};
    end

    acceptsAppBlock ? file : nil
end.compact

if sectionsWithAppBlock.size > 0 && templateJSONFiles.size == sectionsWithAppBlock.size
  puts 'All desired templates have main sections that support app blocks!'
elsif sectionsWithAppBlock.size > 0
  puts 'Only some of the desired templates support app blocks.'
else
  puts 'None of the desired templates support app blocks'
end
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda