Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sup2point0 committed Feb 3, 2025
1 parent be1f415 commit 4a3f93e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 39 deletions.
12 changes: 2 additions & 10 deletions squarkdown/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@


class RoutesConfig
attr_reader :root, :repo, :site
attr_reader :root, :repo
attr_accessor :site

def initialize()
@set = false

log "locating routes..."

# root directory of Squarkdown
Expand All @@ -33,13 +32,6 @@ def initialize()
# default, but can be overridden
@site = repo / "site"
end

def set_site(path)
raise if @set
@site = path
@set = true
end

end


Expand Down
2 changes: 1 addition & 1 deletion squarkdown/core/find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def find_repo_config(from: Routes.repo)
JSON::Validator.validate!(Schema, data)

repo_config.merge!(data)
Routes.set_site(Routes.repo / repo_config["paths / site"])
Routes.site = Routes.repo / repo_config["paths / site"]

return repo_config
end
Expand Down
2 changes: 1 addition & 1 deletion squarkdown/core/render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def inject_style(content, data:, repo_config:)
if path.nil? then return content end

styles = data.style.map do |style|
"@use './#{path}/#{style}' as *;"
"@use './#{File.join(path, style)}' as *;"
end

content = if content.include?("<style") then
Expand Down
21 changes: 16 additions & 5 deletions squarkdown/types/file-data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ValidationError < StandardError
Fields = [:dest, :title, :desc, :head, :capt, :style, :duality, :index, :tags, :date, :clean]


def initialize(source = nil, repo_config:)
def initialize(source = nil, repo_config: nil)
## Meta
@path = source && source.relative_path_from(Routes.repo).to_s
@last_deploy = source && source.mtime
Expand All @@ -60,7 +60,13 @@ def initialize(source = nil, repo_config:)
@desc = nil # capt
@head = nil
@capt = nil
@style = [repo_config["styles / base-style"]]

if repo_config and repo_config["styles / base-style"]
@style = [repo_config["styles / base-style"]]
else
@style = []
end

@duality = nil
@index = []
@tags = nil # index
Expand Down Expand Up @@ -115,11 +121,16 @@ def _parse_(field:, value:, repo_config:)

when :style
styles = _split_(value)
base = repo_config["styles / base-style"]

if styles.delete("#auto")
styles.unshift("article")
elsif !styles.include?("article")
styles.unshift "article"
if base
styles.unshift(base)
end
elsif base
if !styles.include?(base)
styles.unshift(base)
end
end

@style = styles
Expand Down
20 changes: 11 additions & 9 deletions tests/.squarkdown/squarkup.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"$schema": "../../squarkdown/resources/squarkup-schema.json",

"repo": "Squarkdown Tests",
"site": "tests",
"exclude": [

"paths / site": "tests/",
"paths / exclude": [
"/_.*?\\.md",
"/-.*?\\.md"
],
"dest": "export/routes",
"if-no-dir": ["warn"],
"paths / dest": "export/routes/",

"opts / if-no-dir": ["warn"],

"bases": "resources",
"page.svelte": "test.svelte",
"styles": "resources",
"styles / page-styles": "resources",
"fonts": ["testing"]
"bases / path": "resources/",
"bases / page.svelte": "test.svelte",
"styles / path": "resources/",
"styles / page-styles": "resources/",
"fonts / queries": ["testing"]
}
10 changes: 6 additions & 4 deletions tests/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ def test_fields

data = extract_data(
lines: content.split("\n"),
repo_config: RepoConfig
repo_config: RepoConfig,
fill_defaults: true
)

assert data.dest == "testing/fields"
assert data.head == "Testing"
assert data.capt == "A unit test"
assert data.title == "Squarkdown is awesome"
assert data.desc == "Making sure everything works"
assert data.style == ["article", "test"]
assert data.style == ["test"]
assert data.duality == "dark"
assert data.index == ["tests"]
assert data.tags == ["tests", "testing"]
Expand All @@ -87,13 +88,14 @@ def test_fields_default

data = extract_data(
lines: content.split("\n"),
repo_config: RepoConfig
repo_config: RepoConfig,
fill_defaults: true
)

assert data.dest == "testing/defaults"
assert data.head == "Testing"
assert data.title == "Testing"
assert data.style == ["article"]
assert data.style == []
assert data.duality == "light"
assert data.index == []
assert data.tags == []
Expand Down
18 changes: 9 additions & 9 deletions tests/render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
require_relative "../squarkdown/core/find"


def _get_data_
repo_config = nil
def _get_data_(repo_config:)
data = FileData.new
data.update_fields("title = Squarkdown is epic", repo_config:)
data.update_fields("style = #AUTO / testing", repo_config:)
Expand All @@ -17,15 +16,16 @@ def _get_data_

class SquarkupRender < Minitest::Test

Data = _get_data_()

RepoConfig = load_default_repo_config().merge({
"repo" => "Squarkdown Tests",
"site" => "stranger-quarkdown/tests",
"styles" => "resources",
"styles / page-styles" => "resources",
"paths / site" => "stranger-quarkdown/tests/",
"styles / path" => "resources/",
"styles / page-styles" => "resources/",
"styles / base-style" => "basic",
})

Data = _get_data_(repo_config: RepoConfig)


def test_head
content = """# Testing
Expand All @@ -38,14 +38,14 @@ def test_head


def test_style
Routes.set_site(Routes.root / "tests")
Routes.site = Routes.root / "tests"

content = """# Testing
"""

out = inject_style(content, data: Data, repo_config: RepoConfig)

assert out.include?("resources/article")
assert out.include?("resources/basic")
assert out.include?("resources/testing")
end

Expand Down

0 comments on commit 4a3f93e

Please sign in to comment.