slidesutil

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 14 Imported by: 8

README

Google Slides API Helpers in Go

This package provides a set of helper functions and sample code to use with the Google Go Slides API client.

Samples

The Google Slides API samples here have been converted go GO code:

Object IDs

The object ID () should start with a word character [a-zA-Z0-9_] and then followed by any number of the following characters [a-zA-Z0-9_-:]

Documentation

Index

Constants

View Source
const (
	UnitUnspecified                  = "UNIT_UNSPECIFIED"              // The units are unknown.
	UnitEMU                          = "EMU"                           // An English Metric Unit (EMU) is defined as 1/360,000 of a centimeter
	UnitPT                           = "PT"                            // A point, 1/72 of an inch.
	LayoutUnspecified                = "PREDEFINED_LAYOUT_UNSPECIFIED" // Unspecified layout.
	LayoutBlank                      = "BLANK"                         // Blank layout, with no placeholders.
	LayoutCaptionOnly                = "CAPTION_ONLY"                  // Layout with a caption at the bottom.
	LayoutTitle                      = "TITLE"                         // Layout with a title and a subtitle.
	LayoutTitleAndBody               = "TITLE_AND_BODY"                // Layout with a title and body.
	LayoutTitleAndTwoColumns         = "TITLE_AND_TWO_COLUMNS"         // Layout with a title and two columns.
	LayoutTitleOnly                  = "TITLE_ONLY"                    // Layout with only a title.
	LayoutSectionHeader              = "SECTION_HEADER"                // Layout with a section title.
	LayoutSectionTitleAndDescription = "SECTION_TITLE_AND_DESCRIPTION" // Layout with a title and subtitle
	LayoutOneColumnText              = "ONE_COLUMN_TEXT"               // Layout with one title and one body, arranged in a single column.
	LayoutMainPoint                  = "MAIN_POINT"                    // Layout with a main point.
	LayoutBigNumber                  = "BIG_NUMBER"                    // Layout with a big number heading.
	RangeTypeUnspecified             = "RANGE_TYPE_UNSPECIFIED"
	RangeTypeFixedRange              = "FIXED_RANGE"
	RangeTypeStartIndex              = "FROM_START_INDEX"
	RangeTypeAll                     = "ALL"
)

Variables

View Source
var (
	GoogleSlideUnitPoint = "PT"
	ObjectIDFormat       = `^[a-zA-Z0-9_][a-zA-Z0-9_\-:]*$`
)

Functions

func AddFgColor

func AddFgColor(elementID string, fgColor *slides.RgbColor) []*slides.Request

func AlternateRowBgColor

func AlternateRowBgColor(objectID string, rowCount, columnCount int64, evenColorHex, oddColorHex string) ([]*slides.Request, error)

func CommonMarkDataToRequests

func CommonMarkDataToRequests(textboxID string, cmd CommonMarkData, underlineLinks bool) []*slides.Request

func CreateEmptyPresentation

func CreateEmptyPresentation(psv *slides.PresentationsService, filename string) (string, error)

func CreateEmptyPresentationGSS

func CreateEmptyPresentationGSS(gss *GoogleSlidesService, filename string) (string, error)

func CreateEmptyPresentationHTTP

func CreateEmptyPresentationHTTP(googleClient *http.Client, filename string) (string, error)

func CreatePresentation

func CreatePresentation(srv *slides.Service, psv *slides.PresentationsService,
	filename, titleText, subtitleText string) (string, error)

CreatePresentation Creates a new presentation with filename, title and subtitle.

func CreateSlideImageRequestsSidebarRight

func CreateSlideImageRequestsSidebarRight(slideID, imageID, imageURL, sidebarText string) ([]*slides.Request, error)

CreateSlideImageRequestsSidebarRight creates API batch requests to load a main page with optional right sidebar text. `imageID` is optional and will be auto-generated if not provided.

func CreateSlideMainPoint

func CreateSlideMainPoint(srv *slides.Service, psv *slides.PresentationsService, presentationID, titleText string) error

CreateSlideMarkdown creates a slide using Markdown given a PresentationID, title, and markdown body.

func CreateSlideMarkdown

func CreateSlideMarkdown(srv *slides.Service, psv *slides.PresentationsService, presentationID, titleText, bodyMarkdown string, underlineLinks bool) error

CreateSlideMarkdown creates a slide using Markdown given a PresentationID, title, and markdown body.

func CreateSlideRequestLayout

func CreateSlideRequestLayout(predefinedLayout string) *slides.Request

func CreateSlideTitleAndBody

func CreateSlideTitleAndBody(srv *slides.Service, psv *slides.PresentationsService, presentationID, titleText string) (string, error)

CreateSlideTitleAndBody creates a slide using Markdown given a PresentationID, title, and markdown body.

func CreateSlideTitleOnly

func CreateSlideTitleOnly(srv *slides.Service, psv *slides.PresentationsService, presentationID, titleText string) (string, error)

CreateSlideTitleOnly creates a slide using Markdown given a PresentationID and title.

func FormatObjectIDSimple added in v0.1.7

func FormatObjectIDSimple(s string) string

func GoogleSlideDrawRoadmap

func GoogleSlideDrawRoadmap(pageID string, srcCan roadmap.Canvas, outCan SlideCanvasInfo) ([]*slides.Request, error)

func InsertTextRequest

func InsertTextRequest(objectID, text string) *slides.Request

func IsEven

func IsEven(i int) bool

func IsOdd

func IsOdd(i int) bool

func LineStartEndIndexes

func LineStartEndIndexes(cml TextLine, priorLength int64) (int64, int64)

func MustParseRgbColorHex

func MustParseRgbColorHex(hexColor string) *slides.RgbColor

func OptionalColorParseHex

func OptionalColorParseHex(hexColorStr string) (*slides.OptionalColor, error)

func ParseRgbColorHex

func ParseRgbColorHex(hexColor string) (*slides.RgbColor, error)

func RgbColorParseHex

func RgbColorParseHex(hexColorStr string) (*slides.RgbColor, error)

func ShapePropertiesBackgroundFillSimple

func ShapePropertiesBackgroundFillSimple(objectId string, rgbColor *slides.RgbColor) *slides.Request

ShapePropertiesBackgroundFillSimple is a simple shape properties request creator. For more complex uses, use UpdateShapePropertiesRequestUtil

func TextBoxRequestsSimple

func TextBoxRequestsSimple(pageId, elementId, text string, fgColor, bgColor *slides.RgbColor, width, height, locX, locY float64) []*slides.Request

func UpdateParagraphStyleRequestLineSpacing

func UpdateParagraphStyleRequestLineSpacing(objectID string, lineSpacing float64) *slides.Request

func UpdateTableCellPropertiesRequestTableCellBackgroundFill

func UpdateTableCellPropertiesRequestTableCellBackgroundFill(objectID string, rowIndex, columnSpan int64, bgColor *slides.RgbColor) *slides.UpdateTableCellPropertiesRequest

func UpdateTextStyleRequestBold

func UpdateTextStyleRequestBold(objectID string, startIdx, endIdx int64) *slides.Request

func UpdateTextStyleRequestBullet

func UpdateTextStyleRequestBullet(objectID string, startIdx, endIdx int64) *slides.Request

func UpdateTextStyleRequestFontSize

func UpdateTextStyleRequestFontSize(objectID string, dimension slides.Dimension) *slides.Request

func UpdateTextStyleRequestFontSizePT

func UpdateTextStyleRequestFontSizePT(objectID string, pointSize float64) *slides.Request

func UpdateTextStyleRequestLinkURL

func UpdateTextStyleRequestLinkURL(objectID, url string, textRange *slides.Range, underlineLinks bool) *slides.Request

Types

type CanvasFloat64

type CanvasFloat64 struct {
	MinX float64
	MinY float64
	MaxX float64
	MaxY float64
}

func (*CanvasFloat64) ThisX

func (c64 *CanvasFloat64) ThisX(this, min, max float64) (float64, error)

type CommonMarkData

type CommonMarkData struct {
	// contains filtered or unexported fields
}

func NewCommonMarkData

func NewCommonMarkData(cm string) CommonMarkData

func (*CommonMarkData) GoogleSlideTextString

func (cmd *CommonMarkData) GoogleSlideTextString() string

func (*CommonMarkData) Inflate

func (cmd *CommonMarkData) Inflate()

func (*CommonMarkData) LineCount

func (cmd *CommonMarkData) LineCount() int

func (*CommonMarkData) Lines

func (cmd *CommonMarkData) Lines() []TextLine

type CreateLineRequestInfo

type CreateLineRequestInfo struct {
	LineID        string
	PageID        string
	LineCategory  string // STRAIGHT
	Height        float64
	Width         float64
	DimensionUnit string
	LocationX     float64
	LocationY     float64
	DashStyle     string
	Weight        float64
	ColorHex      string
}

func (*CreateLineRequestInfo) Requests

func (info *CreateLineRequestInfo) Requests() ([]*slides.Request, error)

type CreateShapeTextBoxRequestInfo

type CreateShapeTextBoxRequestInfo struct {
	PageId             string
	ObjectId           string
	Width              float64
	Height             float64
	DimensionUnit      string
	LocationX          float64
	LocationY          float64
	LocationUnit       string
	URL                string
	Text               string
	TextURL            string // not implemented yet
	FontBold           bool
	FontItalic         bool
	FontSize           float64
	FontSizeUnit       string
	ParagraphAlignment string // ALIGNMENT_UNSPECIFIED, START, CENTER, END, JUSTIFIED
	ForegroundColorRgb *slides.RgbColor
	BackgroundColorRgb *slides.RgbColor
	ForegroundColorHex string
	BackgroundColorHex string
}

func (*CreateShapeTextBoxRequestInfo) NeedsUpdateShapeProperties

func (info *CreateShapeTextBoxRequestInfo) NeedsUpdateShapeProperties() bool

func (*CreateShapeTextBoxRequestInfo) NeedsUpdateTextStyle

func (info *CreateShapeTextBoxRequestInfo) NeedsUpdateTextStyle() bool

func (*CreateShapeTextBoxRequestInfo) Requests

func (info *CreateShapeTextBoxRequestInfo) Requests() ([]*slides.Request, error)

type GoogleSlidesService

type GoogleSlidesService struct {
	SlidesService        *slides.Service
	PresentationsService *slides.PresentationsService
	// contains filtered or unexported fields
}

func NewGoogleSlidesService

func NewGoogleSlidesService(httpClient *http.Client) (*GoogleSlidesService, error)

func (*GoogleSlidesService) SetHTTPClient

func (gsc *GoogleSlidesService) SetHTTPClient(httpClient *http.Client) error

type LinkInfo

type LinkInfo struct {
	URL   string
	Range *slides.Range
}

type Location

type Location struct {
	SrcAllMinX int64
	SrcAllMaxX int64
	SrcAllWdtX int64
	SrcBoxMinX int64
	SrcBoxMaxX int64
	SrcBoxWdtX int64
	SrcPctWdtX float64
	OutAllMinX float64
	OutAllMaxX float64
	OutAllWdtX float64
	OutBoxMinX float64
	OutBoxMaxX float64
	OutBoxWdtX float64
	BoxOutPctX float64
}

type PresentationCreator

type PresentationCreator struct {
	SlidesClient   *SlidesClient
	Filename       string
	Title          string
	Subtitle       string
	PresentationID string
}

func NewPresentationCreator

func NewPresentationCreator(googHTTPClient *http.Client) (*PresentationCreator, error)

func (*PresentationCreator) Create

func (pc *PresentationCreator) Create(filename, title, subtitle string) (string, error)

func (*PresentationCreator) CreateEmpty

func (pc *PresentationCreator) CreateEmpty(filename string) (string, error)

func (*PresentationCreator) CreateSlideImageSidebarRight

func (pc *PresentationCreator) CreateSlideImageSidebarRight(slideTitle, imageID, imageURL, sidebarText string) error

CreateSlideImageSidebarRight creates a slide for the current presentation. `imageID` is optional and will be auto-generated if not provided.

func (*PresentationCreator) CreateSlideMainPoint

func (pc *PresentationCreator) CreateSlideMainPoint(slideTitle string) error

type SlideCanvasInfo

type SlideCanvasInfo struct {
	BoxFgColor      *slides.RgbColor
	BoxBgColor      *slides.RgbColor
	BoxHeight       float64
	BoxMarginBottom float64
	Canvas          CanvasFloat64
}

func DefaultSlideCanvasInfo

func DefaultSlideCanvasInfo() SlideCanvasInfo

type SlidesClient

type SlidesClient struct {
	GoogleSlidesService *GoogleSlidesService
}

func NewSlidesClient

func NewSlidesClient(googHTTPClient *http.Client) (*SlidesClient, error)

func (*SlidesClient) BatchUpdate

func (sc *SlidesClient) BatchUpdate(presentationID string, batchupdatepresentationrequest *slides.BatchUpdatePresentationRequest) *slides.PresentationsBatchUpdateCall

BatchUpdate is a convenience function to make calling `BatchUpdate` less verbose.

func (*SlidesClient) CreateEmptyPresentation

func (sc *SlidesClient) CreateEmptyPresentation(name string) (string, error)

func (*SlidesClient) CreatePresentation

func (sc *SlidesClient) CreatePresentation(
	filename, titleText, subtitleText string) (string, error)

func (*SlidesClient) CreateSlideMarkdown

func (sc *SlidesClient) CreateSlideMarkdown(presentationID, titleText, bodyMarkdown string, underlineLinks bool) error

func (*SlidesClient) CreateSlideTitleAndBody

func (sc *SlidesClient) CreateSlideTitleAndBody(presentationID string, filename string) (string, error)

CreateSlideTitleAndBody is a convenience function.

type TextBoxInfoSimple

type TextBoxInfoSimple struct {
	PageID     string
	ElementID  string
	Text       string
	FgColorHex string
	BgColorHex string
	Width      float64
	Height     float64
	LocationX  float64
	LocationY  float64
}

type TextLine

type TextLine struct {
	CommonMarkText   string
	GoogleSlideText  string
	IsBullet         bool
	IsBold           bool
	Links            []LinkInfo
	Inflated         bool
	GoogleIndexStart int64
	GoogleIndexEnd   int64
}

func InflateCommonMarkToGoogleSlides

func InflateCommonMarkToGoogleSlides(cml TextLine) TextLine

func Split

func Split(cm string) []TextLine

type UpdateShapePropertiesRequestUtil

type UpdateShapePropertiesRequestUtil struct {
	Fields                       []string
	UpdateShapePropertiesRequest *slides.UpdateShapePropertiesRequest
}

func NewUpdateShapePropertiesRequestUtil

func NewUpdateShapePropertiesRequestUtil(objectId string) UpdateShapePropertiesRequestUtil

func (*UpdateShapePropertiesRequestUtil) AddBackgroundSolidFill

func (util *UpdateShapePropertiesRequestUtil) AddBackgroundSolidFill(rgbColor *slides.RgbColor)
func (util *UpdateShapePropertiesRequestUtil) AddLink(link *slides.Link)

func (*UpdateShapePropertiesRequestUtil) Request

type UpdateTextStyle

type UpdateTextStyle struct {
	ObjectID           string
	RowIndex           int64
	ColumnIndex        int64
	ForegroundColorHex string
	Bold               bool
	FontFamily         string
	FontSizeMagnitude  float64
	FontSizeUnit       string
	TextRangeType      string
	Fields             string
}

func (*UpdateTextStyle) Request

func (item *UpdateTextStyle) Request() (*slides.Request, error)

func (*UpdateTextStyle) RequestsColumnSpan

func (item *UpdateTextStyle) RequestsColumnSpan(columnSpan int64) ([]*slides.Request, error)

Directories

Path Synopsis
create_image
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example Adding Image to a Slide: https://developers.google.com/slides/how-tos/add-image
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example Adding Image to a Slide: https://developers.google.com/slides/how-tos/add-image
create_line
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
create_table
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
create_textbox
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
create_textboxes_single_column
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
format_markdown
Formatting text with the Google Slides API Video: https://www.youtube.com/watch?v=_O2aUCJyCoQ
Formatting text with the Google Slides API Video: https://www.youtube.com/watch?v=_O2aUCJyCoQ
format_text
Formatting text with the Google Slides API Video: https://www.youtube.com/watch?v=_O2aUCJyCoQ This intentially does not use any of the helpers in https://github.com/grokify/googleutil/slidesutil/v1/ See the `examples/format_markdown` for how to use the slidesutil request helpers.
Formatting text with the Google Slides API Video: https://www.youtube.com/watch?v=_O2aUCJyCoQ This intentially does not use any of the helpers in https://github.com/grokify/googleutil/slidesutil/v1/ See the `examples/format_markdown` for how to use the slidesutil request helpers.
hello_world
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example
Go example that covers: Quickstart: https://developers.google.com/slides/quickstart/go Basic writing: adding a text box to slide: https://developers.google.com/slides/samples/writing Using SDK: https://github.com/google/google-api-go-client/blob/master/slides/v1/slides-gen.go Creating and Managing Presentations https://developers.google.com/slides/how-tos/presentations Adding Shapes and Text to a Slide: https://developers.google.com/slides/how-tos/add-shape#example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL