diff --git a/app/controllers/liquid_tags_controller.rb b/app/controllers/liquid_tags_controller.rb new file mode 100644 index 000000000..6e2db6e61 --- /dev/null +++ b/app/controllers/liquid_tags_controller.rb @@ -0,0 +1,13 @@ +class LiquidTagsController < ApplicationController + before_action :authenticate_user! + + FILTER_REGEX = /^(?:NullTag|Liquid::)/.freeze + + def index + custom_tags = Liquid::Template.tags.filter_map do |name, tag| + name unless tag.match?(FILTER_REGEX) + end.sort + + render json: { liquid_tags: custom_tags } + end +end diff --git a/config/routes.rb b/config/routes.rb index 8d1fbca53..6c24e311e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -284,6 +284,8 @@ Rails.application.routes.draw do resources :profiles, only: %i[update] resources :profile_field_groups, only: %i[index], defaults: { format: :json } + resources :liquid_tags, only: %i[index], defaults: { format: :json } + get "/verify_email_ownership", to: "email_authorizations#verify", as: :verify_email_authorizations get "/search/tags" => "search#tags" get "/search/chat_channels" => "search#chat_channels" diff --git a/spec/requests/liquid_tags_request_spec.rb b/spec/requests/liquid_tags_request_spec.rb new file mode 100644 index 000000000..ee46995d2 --- /dev/null +++ b/spec/requests/liquid_tags_request_spec.rb @@ -0,0 +1,28 @@ +require "rails_helper" + +RSpec.describe "LiquidTags", type: :request do + describe "GET /liquid_tags" do + context "when not signed in do" do + it "returns a list of all custom Liquid tags" do + get liquid_tags_path + + expect(response).to have_http_status(:unauthorized) + end + end + + context "when signed in" do + let(:user) { create(:user) } + + before { sign_in(user) } + + it "returns an array of all custom Liquid tags", :aggregate_failures do + get liquid_tags_path + + expect(response).to have_http_status(:ok) + json = response.parsed_body + expect(json["liquid_tags"]).to be_an_instance_of(Array) + expect(json["liquid_tags"]).not_to be_empty + end + end + end +end