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 all 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
18 changes: 11 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
name: Docs

on:
pull_request:
branches:
- main
push:
branches:
- main

permissions:
contents: write

jobs:
deploy:
name: Deploy
runs-on: ubuntu-22.04
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
36 changes: 36 additions & 0 deletions src/api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,42 @@ 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.update_counter
# represent.parse_string("def foo\n 1 + 1\nend")
# represent.represent
# ```
def update_data(new_data : Array(String))
TestVisitor.data = new_data
end

# Allows changing the value of the counter which is which number of the placeholder item gets.
# When wanting to represent brand new code, this variable has to be changed to one.
# When the method is called without any argumments will it defualt to one.
#
# Example:
# ```
# represent = Representer.new
# represent.parse_string("def foo\n 1 + 1\nend")
# represent.represent
# represent.update_data([] of String)
# represent.update_counter(1)
# represent.parse_string("def foo\n 1 + 1\nend")
# represent.represent
# ```
def update_counter(new_counter : Int32 = 1)
TestVisitor.counter = new_counter
end

private def parse(content : String) : Crystal::ASTNode
begin
content += "\n"
Expand Down
4 changes: 4 additions & 0 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ 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)
representer.update_counter()
8 changes: 8 additions & 0 deletions src/representer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class TestVisitor < Crystal::Transformer
@@data
end

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

def self.counter=(new_counter : Int32)
@@counter = new_counter
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