README.md in storyblok-2.0.5 vs README.md in storyblok-2.0.6

- old
+ new

@@ -25,11 +25,11 @@ # Without cache client = Storyblok::Client.new(token: 'YOUR_TOKEN') # Optionally set a cache client redis = Redis.new(url: 'redis://localhost:6379') -cache = Storyblok::Cache::Redis.new(redis: Redis.current) +cache = Storyblok::Cache::Redis.new(redis: redis) client = Storyblok::Client.new(cache: cache, token: 'YOUR_TOKEN') # Get a story client.story('home') ``` @@ -137,9 +137,42 @@ ### Delete a story ```ruby client.delete("spaces/{space_id}/stories/{story_id}") +``` + +## Rendering of richtext fields + +This SDK comes with a rendering service for richtext fields of Storyblok to get html output. + +### Rendering a richtext field + +```ruby +client.render(data.richtext_field) +``` + +### Define a component renderer + +Storyblok's richtext field also let's you insert content blocks. To render these blocks you can define a Lambda. + +```ruby +# Option 1: Define the resolver when initializing +client = Storyblok::Client.new( + component_resolver: ->(component, data) => { + case component + when 'button' + "<button>#{data['text']}</button>" + when 'your_custom_component' + "<div class="welcome">#{data['welcome_text']}</div>" + end + } +) + +# Option 2: Define the resolver afterwards +client.set_component_resolver(->(component, data) { + "#{component}" +}) ``` ### License