Skip to content

Commit

Permalink
Update path filtering, remove root node
Browse files Browse the repository at this point in the history
  • Loading branch information
CuddlyBunion341 committed Oct 22, 2024
1 parent 720fbd2 commit 42ecce2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/controllers/moirai/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ module Moirai
class PagesController < ApplicationController
def index
i18n_file_paths = I18n.load_path
file_contents = i18n_file_paths.map { |path| [path, parse_file(path)] }.to_h
yml_file_paths = i18n_file_paths.select { |path| path.end_with?(".yml") || path.end_with?(".yaml") }
file_contents = yml_file_paths.map { |path| [path, parse_file(path)] }.to_h
render json: file_contents
end

private

def parse_file(path)
is_yml_path = path.end_with?(".yml") || path.end_with?(".yaml")
return unless is_yml_path
yaml_content = YAML.load_file(path)
flatten_hash(yaml_content)
root_key = yaml_content.keys.first
flatten_hash(yaml_content[root_key])
end

def flatten_hash(hash, parent_key = '', result = {})
Expand Down

0 comments on commit 42ecce2

Please sign in to comment.