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

IR Generation #820

Draft
wants to merge 72 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
09864e4
Create ir_example.html
rich-iannone Jul 28, 2021
8b70ae2
Create render_ir.R
rich-iannone Jul 28, 2021
3aabf9b
Update DESCRIPTION
rich-iannone Jul 28, 2021
eca725c
Update render_ir.R
rich-iannone Jul 28, 2021
39a3ab0
Update render_ir.R
rich-iannone Jul 28, 2021
f55df8d
Add the `create_col_group_ir()` util fn
rich-iannone Jul 28, 2021
625c362
Update ir_example.html
rich-iannone Jul 28, 2021
b202bc0
Update render_ir.R
rich-iannone Jul 29, 2021
b1e7127
Put `colgroup_element` in a tagList
rich-iannone Jul 29, 2021
583e9d5
Add the `create_heading_ir()` function
rich-iannone Jul 29, 2021
d0ee0ff
Add the `create_columns_ir()` function
rich-iannone Jul 29, 2021
c6b3213
Update ir_example.html
rich-iannone Jul 29, 2021
e3ebd60
Modify tag names
rich-iannone Jul 29, 2021
003ae5a
Return empty tagList is columns are hidden
rich-iannone Jul 29, 2021
6d6db29
Modify tag names for column labels loc
rich-iannone Jul 29, 2021
eacff8e
Add the `create_body_ir()` function
rich-iannone Jul 29, 2021
66c7d41
Remove TODO note
rich-iannone Jul 29, 2021
5354f30
Update ir_example.html
rich-iannone Jul 30, 2021
929d673
Update ir_example.html
rich-iannone Aug 2, 2021
2b5d74c
Update utils_render_ir.R
rich-iannone Aug 2, 2021
03c6a66
Update ir_example.html
rich-iannone Aug 3, 2021
51d77fc
Add `combine_as_ir()` util fn
rich-iannone Aug 3, 2021
c31bd26
Ensure that stub role is set for summary rows
rich-iannone Aug 3, 2021
8a60c75
Revise `create_heading_ir()`
rich-iannone Aug 3, 2021
22cf163
Update utils_render_ir.R
rich-iannone Aug 3, 2021
01bf3ea
Update render_ir.R
rich-iannone Aug 3, 2021
bbc9eaa
Add `stub` role in more elements
rich-iannone Aug 3, 2021
b29ad3c
Reformat footnotes in IR
rich-iannone Aug 3, 2021
889e3a5
Generate the `table_defs` object
rich-iannone Aug 3, 2021
97a9abb
Add the `config` element to the IR
rich-iannone Aug 3, 2021
fdf92af
Remove unneeded stmts
rich-iannone Aug 4, 2021
8c4a540
Implement styles in spanner elements
rich-iannone Aug 4, 2021
a09040d
Implement styling for column labels
rich-iannone Aug 4, 2021
4ac52a3
Implement styling for stubhead label
rich-iannone Aug 4, 2021
662e092
Update ir_example.html
rich-iannone Aug 4, 2021
0d0d5f5
Implement styling in footnotes location
rich-iannone Aug 4, 2021
e19018b
Add `data` arg to `combine_as_ir()`
rich-iannone Aug 4, 2021
0217e4f
Update render_ir.R
rich-iannone Aug 4, 2021
9df9f93
Rewrite implementation of config element
rich-iannone Aug 4, 2021
d97eab7
Remove stmt that returns an empty tagList
rich-iannone Aug 4, 2021
b67a58d
Refactor `combine_as_ir()`
rich-iannone Aug 4, 2021
9666427
Return IR as a character vector
rich-iannone Aug 4, 2021
523c067
Apply role as needed to stub cells
rich-iannone Aug 4, 2021
3d040b7
Move position of `role` attr for summary rows
rich-iannone Aug 4, 2021
fe0ea6c
Render all config keys in kebab case
rich-iannone Aug 9, 2021
e01472a
Modify order of `option_names`
rich-iannone Aug 9, 2021
a478771
Create ir-generation.R
rich-iannone Aug 9, 2021
e9574a6
Use `mark` tag to enclose rendered footnote marks
rich-iannone Aug 9, 2021
9824c8c
Use `mark` tag instead of `i` in footer area
rich-iannone Aug 9, 2021
e70ab27
Update ir-generation.R
rich-iannone Aug 9, 2021
630009c
Merge branch 'master' into ir-generation
rich-iannone Aug 9, 2021
067d168
Add `footnote-id` attr to all <mark> elements
rich-iannone Aug 9, 2021
51132d4
Disable failing tests for HTML output
rich-iannone Aug 9, 2021
4d8f33a
Update ir-generation.R
rich-iannone Aug 9, 2021
ccdf755
Update ir_example.html
rich-iannone Aug 9, 2021
4dfad82
Set `role` names in kebab case
rich-iannone Aug 9, 2021
e9fe61c
Update utils_render_html.R
rich-iannone Aug 13, 2021
1553e45
Update utils_render_ir.R
rich-iannone Aug 13, 2021
fa84a20
Update utils_render_html.R
rich-iannone Aug 13, 2021
f4752f3
Update utils_render_ir.R
rich-iannone Aug 13, 2021
31748e8
Update ir-generation.R
rich-iannone Aug 16, 2021
fcf4209
Add closing tag for <config> element
rich-iannone Aug 17, 2021
f9558f1
Update ir-generation.R
rich-iannone Aug 17, 2021
86ddb1e
Improve column counting routine
rich-iannone Aug 17, 2021
fc049d7
Update utils_render_ir.R
rich-iannone Aug 17, 2021
32dd92a
Update ir-generation.R
rich-iannone Aug 17, 2021
6fa2999
Update utils_render_ir.R
rich-iannone Aug 17, 2021
3d686dd
Update ir-generation.R
rich-iannone Aug 17, 2021
b531976
Use `class` instead of `loc` attr name
rich-iannone Aug 19, 2021
326b59d
Modify XPATH expression
rich-iannone Aug 19, 2021
b791a0f
Remove stmts that get table dims
rich-iannone Aug 25, 2021
b0c1058
Simplify `combine_as_ir()`
rich-iannone Aug 25, 2021
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
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Collate:
'print.R'
'reexports.R'
'render_as_html.R'
'render_ir.R'
'resolver.R'
'shiny.R'
'summary_rows.R'
Expand All @@ -109,6 +110,7 @@ Collate:
'utils_render_common.R'
'utils_render_footnotes.R'
'utils_render_html.R'
'utils_render_ir.R'
'utils_render_latex.R'
'utils_render_rtf.R'
'zzz.R'
62 changes: 62 additions & 0 deletions R/render_ir.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#' Transform a **gt** table object to its intermediate representation (IR)
#'
#' Take a `gt_tbl` table object and transform it to valid gt IR text.
#'
#' @param data A table object that is created using the `gt()` function.
#'
#' @return A character object.
#'
#' @noRd
render_to_ir <- function(data,
target = c("html", "latex", "rtf")) {

target <- match.arg(target)

data <- build_data(data = data, context = target)

# Composition of IR -------------------------------------------------------

# Upgrade `_styles` to gain a `html_style` column with CSS style rules
data <- add_css_styles(data = data)

# Create the column group component
colgroup_component <- create_col_group_ir(data = data)

# Create the heading component
heading_component <- create_heading_ir(data = data)

# Create the columns component
columns_component <- create_columns_ir(data = data)

# Create the body component
body_component <- create_body_ir(data = data)

# Create the source notes component
source_notes_component <- create_source_notes_ir(data = data)

# Create the footnotes component
footnotes_component <- create_footnotes_ir(data = data)

# Compose the IR
combine_as_ir(
data = data,
target = target,
colgroup_component = colgroup_component,
heading_component = heading_component,
columns_component = columns_component,
body_component = body_component,
source_notes_component = source_notes_component,
footnotes_component = footnotes_component
)
}

get_tr_count_from_component <- function(html_string) {

length(
xml2::xml_find_all(
xml2::read_html(
as.character(html_string)),
xpath = ".//tr"
)
)
}
2 changes: 1 addition & 1 deletion R/utils_render_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
footnote_mark_to_html <- function(mark) {

as.character(
htmltools::tagList(htmltools::tags$sup(class = "gt_footnote_marks", mark))
htmltools::tags$sup(mark)
)
}

Expand Down
Loading