Skip to content

Commit ff111a6

Browse files
committed
Update Readme
1 parent a985915 commit ff111a6

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

README.md

+38-8
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,75 @@
11
# AttributedString
2+
[![Ruby](https://github.com/instruct-rb/attributed-string/actions/workflows/ruby.yml/badge.svg)](https://github.com/instruct-rb/attributed-string/actions/workflows/ruby.yml)
23

34
An attributed string implementation for Ruby.
45

5-
An attributed string contains key-value pairs known as attributes that specify additional information related to ranges of characters within the string. Attributed strings support any key-value pair, but are often used for:
6+
--
7+
🚧 This gem is in development, and its behaviour might still change before 1.0 🚧
8+
9+
---
10+
11+
12+
An attributed string contains key-value pairs known as attributes that specify additional information related to ranges of characters within the string. Attributed strings support any key-value pair, but are often used for:
613

714
- Rendering attributes such as font, color, and other details.
8-
- Attributes for inline-attachments such as images, videos, files, etc.
15+
- Attributes for inline-attachments such as images, videos, files, etc.
916
- Semantic attributes such as link URLs or tool-tip information
10-
- Language attributes to support automatic gender agreement or verb agreement.
17+
- Language attributes to support automatic gender agreement or verb agreement.
1118
- Accessibility attributes that provide information for assistive technologies
1219
- Custom attributes you define
1320

14-
You will typically need to create a presenter for an attributed string, as the default shows no attribute information and inspect shows all attributes.
21+
You will typically need to create a presenter for an attributed string, as the default shows no attribute information and inspect shows all attributes.
22+
23+
This gem is inspired by Apple's [NSAttributedString](https://developer.apple.com/documentation/foundation/nsattributedstring).
1524

1625
## Installation
1726

1827
Add this line to your application's Gemfile:
1928

2029
```ruby
21-
gem 'attributed-string', github: 'instruct-rb/attributed-string', branch: 'main'
30+
gem 'attributed-string'
2231
```
2332

2433

2534
## Usage
2635

27-
🚧 This gem is a work in progress and the API may change before 1.0.
2836

2937
```ruby
3038
using AttributedString::Refinements
3139
hello_world1 = AttributedString.new('Hello, World!', color: :red, font: 'Helvetica' )
3240
hello_world2 = 'Hello, World!'.to_attr_s(color: :red, font: 'Helvetica')
33-
puts hello_world1 == hello_world2 # true
41+
puts hello_world1 == hello_world2
42+
# => true
43+
44+
hello_world1.add_attrs(0..4, color: :blue)
45+
hello_world1 += "!!"
46+
puts hello_world1.inspect
47+
# => { color: blue, font: "Helvetica" }Hello{ color: red}, World!{ -color, -font }!!
48+
49+
puts hello_world1.attrs_at(0)
50+
# => { color: blue, font: "Helvetica" }
3451
```
3552

3653
## Attachments
3754

3855
```ruby
3956
hello_world = AttributedString.new('Hello, World!')
57+
4058
hello_world.add_attachment("any ruby object", position: string.length)
41-
puts hello_world # => "Hello, World! "
59+
60+
# Adding an attachment inserts the Object Replacement Character into the
61+
# string, in most fonts it will show as a space
62+
puts hello_world
63+
# => "Hello, World! "
4264
puts hello_world.attachments # => ["any ruby object"]
65+
66+
# Deleting the character from the string removes the attachment
4367
hello_world[-1..-1] = ''
4468
puts hello_world.attachments # => []
4569
```
70+
71+
## More Examples
72+
See the [test suite](./test).
73+
74+
## Used By
75+
- [Instruct](https://github.com/instruct-rb/instruct) - Instruct LLMs to do what you want in Ruby

0 commit comments

Comments
 (0)