Sha256: 4abf535e4b5f8f13dc17386794e2de337e17f86f598a6667be535f89b0ba578d

Contents?: true

Size: 1.83 KB

Versions: 7

Compression:

Stored size: 1.83 KB

Contents

# abbreviato

[![Continuous Integration](https://github.com/zendesk/abbreviato/actions/workflows/actions.yml/badge.svg)](https://github.com/zendesk/abbreviato/actions/workflows/actions.yml)
[![Security](https://github.com/zendesk/abbreviato/actions/workflows/security.yml/badge.svg)](https://github.com/zendesk/abbreviato/actions/workflows/security.yml)
[![Gem Version](https://img.shields.io/gem/v/abbreviato.svg)](https://rubygems.org/gems/abbreviato)

*abbreviato* is a Ruby library for truncating HTML strings keeping the markup valid. It is a fork of [jorgemanrubia/truncato](https://github.com/jorgemanrubia/truncato) but focused on truncating to a bytesize, not on a per-character basis.

## Installing

In your `Gemfile`

```ruby
gem 'abbreviato'
```

## Usage

```ruby
truncated_string, was_truncated = Abbreviato.truncate("<p>some text</p>", max_length: 4)
# => ["<p>s...</p>", true]
```

The configuration options are:

* `max_length`: The size, in bytes, to truncate (`30` by default)
* `tail`: The string to append when the truncation occurs ('&hellip;' by default).
* `fragment`: Indicates whether the document to be truncated is an HTML fragment or an entire document (with `HTML`, `HEAD` & `BODY` tags). Setting to true prevents automatic
addition of these tags if they are missing. Defaults to `true`.

## Performance

Abbreviato was designed with performance in mind. Its main motivation was that existing libs couldn't truncate a multiple-MB document into a few-KB one in a reasonable time. It uses the [Nokogiri](http://nokogiri.org/) SAX parser.

## Running the tests

```ruby
bundle exec rake
```

## Running a single test

```ruby
rspec spec/abbreviato/abbreviato_spec.rb
rspec spec/abbreviato/abbreviato_spec.rb:357
```

## Running all checks

```ruby
bundle exec rake spec
```

## Contribute

Follow our [contribution guidelines](CONTRIBUTING.md).

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
abbreviato-3.2.0 README.md
abbreviato-3.1.4 README.md
abbreviato-3.1.1 README.md
abbreviato-3.1.0 README.md
abbreviato-3.0.0 README.md
abbreviato-2.0.0 README.md
abbreviato-1.0.0 README.md