Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.2.1]: Fix deploy script and allow to clear data #18

Merged
merged 7 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
name: Docs
on: [push]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But wouldn't this overwrite the docs whenever a PR is opened? That would mean that the docs are potentially temporarily incorrect

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will fix so it only generates new docs on push to the main branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: write

jobs:
deploy:
Expand All @@ -15,11 +11,16 @@ jobs:
container:
image: crystallang/crystal
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- name: Checkout 🛎️
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- name: Install rsync 📚
run: |
apt-get update && apt-get install -y rsync
- name: Build docs
run: crystal docs --project-name Representer --project-version 1.2.0-Dev
run: crystal docs --project-name Representer --project-version 1.2.0
- name: Deploy docs
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: JamesIves/github-pages-deploy-action@a1ea191d508feb8485aceba848389d49f80ca2dc
with:
branch: gh-pages
folder: docs # The folder the action should deploy.
clean: true
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.2.1

- Fix github pages
- Clear class data when representation is done
- Add method which allows clearing of data

# 1.2.0

## Improvements
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: representer
version: 1.2.0
version: 1.2.1

authors:
- Meatball
Expand Down
17 changes: 17 additions & 0 deletions src/api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ class Representer
TestVisitor.debug.to_json
end

# Allows changing the value of the data variable which is what is
# holding all names when representation.
# When wanting to represent brand new code, this variable has to be cleared
#
# Example:
# ```
# represent = Representer.new
# represent.parse_string("def foo\n 1 + 1\nend")
# represent.represent
# represent.update_data([] of String)
# represent.parse_string("def foo\n 1 + 1\nend")
# represent.represent
# ```
def update_data(new_data : Array(String))
TestVisitor.data = new_data
end

private def parse(content : String) : Crystal::ASTNode
begin
content += "\n"
Expand Down
3 changes: 3 additions & 0 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ unless directory.is_a?(Path)
end

representer.represent

File.write(directory / "mapping.json", representer.mapping_json)
File.write(directory / "representation.json", representer.representation_json)
File.write(directory / "representation.txt", representer.representation)

if options[:debug]
File.write(directory / "debug.json", representer.debug_json)
end

representer.update_data([] of String)
4 changes: 4 additions & 0 deletions src/representer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class TestVisitor < Crystal::Transformer
@@data
end

def self.data=(new_data : Array(String))
@@data = new_data
end

def initialize(data = [] of String, debug = [] of Tuple(String, String))
@@debug += debug
@@data += data
Expand Down
2 changes: 1 addition & 1 deletion tests/example-multiple-files/expected_mapping.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"PLACEHOLDER_1":"Helpers","PLACEHOLDER_2":"mod","PLACEHOLDER_3":"x","PLACEHOLDER_4":"y","PLACEHOLDER_5":"Leap","PLACEHOLDER_6":"is_leap_year?","PLACEHOLDER_7":"year"}
{"PLACEHOLDER_1":"Leap","PLACEHOLDER_2":"is_leap_year?","PLACEHOLDER_3":"year","PLACEHOLDER_4":"Helpers","PLACEHOLDER_5":"mod","PLACEHOLDER_6":"x","PLACEHOLDER_7":"y"}
14 changes: 7 additions & 7 deletions tests/example-multiple-files/expected_representation.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module PLACEHOLDER_1
def PLACEHOLDER_2(PLACEHOLDER_3, PLACEHOLDER_4)
PLACEHOLDER_3 % PLACEHOLDER_4
class PLACEHOLDER_1
extend PLACEHOLDER_4
def PLACEHOLDER_2(PLACEHOLDER_3)
PLACEHOLDER_5(PLACEHOLDER_3, 4)
end
end
class PLACEHOLDER_5
extend PLACEHOLDER_1
def PLACEHOLDER_6(PLACEHOLDER_7)
PLACEHOLDER_2(PLACEHOLDER_7, 4)
module PLACEHOLDER_4
def PLACEHOLDER_5(PLACEHOLDER_6, PLACEHOLDER_7)
PLACEHOLDER_6 % PLACEHOLDER_7
end
end