Module: Blogue

Defined in:
lib/blogue.rb,
lib/blogue/engine.rb,
lib/blogue/version.rb,
app/models/blogue/post.rb,
lib/blogue/kramdown_template_handler.rb

Defined Under Namespace

Classes: Engine, KramdownTemplateHandler, Post

Constant Summary collapse

DEFAULT_AUTHOR_NAME =
`whoami`.strip.freeze
DEFAULT_POSTS_PATH =
'app/posts'.freeze
DEFAULT_ASSETS_PATH =
-> { "#{Blogue.posts_path}/assets" }
DEFAULT_COMPUTE_POST_CACHE_KEY =
-> post {
  Digest::MD5.hexdigest([post.id, post.author_name, post.body].join)
}
DEFAULT_ROUGE_KRAMDOWN_OPTIONS =
{
  :syntax_highlighter => :rouge,
  :syntax_highlighter_opts => { default_lang: 'ruby' }.freeze
}.freeze
VERSION =
"0.3.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.assets_pathObject

Returns the value of attribute assets_path.



18
19
20
# File 'lib/blogue.rb', line 18

def assets_path
  @assets_path
end

.author_nameObject

Returns the value of attribute author_name.



18
19
20
# File 'lib/blogue.rb', line 18

def author_name
  @author_name
end

.cache_keyObject (readonly)

Returns the value of attribute cache_key.



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

def cache_key
  @cache_key
end

.compute_post_cache_keyObject

Returns the value of attribute compute_post_cache_key.



18
19
20
# File 'lib/blogue.rb', line 18

def compute_post_cache_key
  @compute_post_cache_key
end

.markdown_template_handlerObject (readonly)

Returns the value of attribute markdown_template_handler.



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

def markdown_template_handler
  @markdown_template_handler
end

.posts_cache_keysObject (readonly)

Returns the value of attribute posts_cache_keys.



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

def posts_cache_keys
  @posts_cache_keys
end

.posts_pathObject

Returns the value of attribute posts_path.



18
19
20
# File 'lib/blogue.rb', line 18

def posts_path
  @posts_path
end

.started_atObject (readonly)

Returns the value of attribute started_at.



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

def started_at
  @started_at
end

Class Method Details

.compute_cache_keys!Object



40
41
42
43
44
45
46
47
48
# File 'lib/blogue.rb', line 40

def compute_cache_keys!
  @posts_cache_keys = Hash[Post.all.map { |p|
    [p.id.freeze, Blogue.compute_post_cache_key.(p).freeze]
  }].freeze

  @cache_key = Digest::MD5.hexdigest(
    @posts_cache_keys.values.sort.join
  ).freeze
end

.detect_markdown_template_handlerObject



54
55
56
57
58
59
60
# File 'lib/blogue.rb', line 54

def detect_markdown_template_handler
  if defined?(Kramdown) && defined?(Rouge)
    KramdownTemplateHandler.new(DEFAULT_ROUGE_KRAMDOWN_OPTIONS)
  elsif defined?(Kramdown)
    KramdownTemplateHandler.new
  end
end

.markdown_template_preprocessor=(preprocessor) ⇒ Object



50
51
52
# File 'lib/blogue.rb', line 50

def markdown_template_preprocessor=(preprocessor)
  self.markdown_template_handler.preprocessor = preprocessor
end

.setup_defaults!Object



30
31
32
33
34
35
36
37
38
# File 'lib/blogue.rb', line 30

def setup_defaults!
  self.author_name = DEFAULT_AUTHOR_NAME
  self.posts_path = DEFAULT_POSTS_PATH
  self.assets_path = DEFAULT_ASSETS_PATH
  self.compute_post_cache_key = DEFAULT_COMPUTE_POST_CACHE_KEY

  @markdown_template_handler = detect_markdown_template_handler
  @started_at = Time.current.freeze
end