Module: Pressroom

Defined in:
lib/pressroom.rb,
lib/pressroom/feed.rb,
lib/pressroom/engine.rb,
lib/pressroom/errors.rb,
lib/pressroom/current.rb,
lib/pressroom/version.rb,
app/models/pressroom/tag.rb,
app/models/pressroom/post.rb,
lib/pressroom/blocks/schema.rb,
lib/pressroom/configuration.rb,
app/models/pressroom/tagging.rb,
app/models/pressroom/category.rb,
lib/pressroom/blocks/registry.rb,
lib/pressroom/blocks/renderer.rb,
lib/pressroom/built_in_blocks.rb,
lib/pressroom/transliteration.rb,
lib/pressroom/blocks/sanitizer.rb,
lib/pressroom/blocks/definition.rb,
app/jobs/pressroom/application_job.rb,
app/helpers/pressroom/blocks_helper.rb,
lib/pressroom/blocks/text_extractor.rb,
app/models/concerns/pressroom/scoped.rb,
app/models/concerns/pressroom/sluggable.rb,
app/models/pressroom/application_record.rb,
app/helpers/pressroom/application_helper.rb,
app/mailers/pressroom/application_mailer.rb,
app/models/concerns/pressroom/authorable.rb,
app/controllers/pressroom/tags_controller.rb,
app/controllers/pressroom/posts_controller.rb,
app/controllers/pressroom/uploads_controller.rb,
app/controllers/pressroom/categories_controller.rb,
app/controllers/pressroom/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, Authorable, Blocks, BlocksHelper, BuiltInBlocks, Scoped, Sluggable, Transliteration Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, CategoriesController, Category, Configuration, ConfigurationError, Current, Engine, Error, Feed, Post, PostsController, Tag, Tagging, TagsController, UnknownBlockError, UploadsController

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.active_storage?Boolean

ActiveStorage is optional. When it is absent the image block still renders a picture from a URL; there is simply nowhere to upload to.

Returns:

  • (Boolean)


84
85
86
# File 'lib/pressroom.rb', line 84

def active_storage?
  defined?(ActiveStorage::Blob).present?
end

.configObject



20
21
22
# File 'lib/pressroom.rb', line 20

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



24
25
26
27
# File 'lib/pressroom.rb', line 24

def configure
  yield config
  config
end

.current_scopeObject

The publication the current unit of work belongs to. Nil means the application's single publication, which is what an app that never uses publications always sees.



41
42
43
# File 'lib/pressroom.rb', line 41

def current_scope
  Current.scope
end

.register_block(type, &block) ⇒ Object

Public API: registers a block type.

Pressroom.register_block :callout do |b|
b.tool "Callout"
b.schema { string :title, required: true }
b.partial "pressroom/blocks/callout"
end


62
63
64
# File 'lib/pressroom.rb', line 62

def register_block(type, &block)
  registry.register(type, &block)
end

.registryObject



34
35
36
# File 'lib/pressroom.rb', line 34

def registry
  @registry ||= Blocks::Registry.new
end

.rendererObject

Built per call rather than memoized: configuration may change at runtime in tests, and construction is cheap.



68
69
70
71
72
73
74
75
76
# File 'lib/pressroom.rb', line 68

def renderer
  Blocks::Renderer.new(
    registry: registry,
    sanitizer: Blocks::Sanitizer.new(tags: config.sanitizer_tags,
                                     attributes: config.sanitizer_attributes),
    strategy: config.resolved_unknown_block_strategy,
    logger: defined?(Rails) ? Rails.logger : nil
  )
end

.reset_configuration!Object

Test helper: restores pristine defaults between examples.



30
31
32
# File 'lib/pressroom.rb', line 30

def reset_configuration!
  @config = Configuration.new
end

.text_extractorObject



78
79
80
# File 'lib/pressroom.rb', line 78

def text_extractor
  Blocks::TextExtractor.new(registry: registry)
end

.with_scope(owner) ⇒ Object

Runs a block against one publication. Nests, and restores the previous publication even when the block raises.



47
48
49
50
51
52
53
# File 'lib/pressroom.rb', line 47

def with_scope(owner)
  previous = Current.scope
  Current.scope = owner
  yield
ensure
  Current.scope = previous
end