Module: Syntropy

Extended by:
Utilities
Defined in:
lib/syntropy.rb,
lib/syntropy/app.rb,
lib/syntropy/utils.rb,
lib/syntropy/errors.rb,
lib/syntropy/module.rb,
lib/syntropy/version.rb,
lib/syntropy/json_api.rb,
lib/syntropy/markdown.rb,
lib/syntropy/side_run.rb,
lib/syntropy/file_watch.rb,
lib/syntropy/routing_tree.rb,
lib/syntropy/connection_pool.rb,
lib/syntropy/request_extensions.rb

Defined Under Namespace

Modules: RequestExtensions, SideRun, Utilities Classes: App, ConnectionPool, Error, JSONAPI, Module, ModuleLoader, RoutingTree, ValidationError

Constant Summary collapse

Status =
Qeweney::Status
GREEN =
"\e[32m"
CLEAR =
"\e[0m"
YELLOW =
"\e[33m"
"\n"\
"  #{GREEN}\n"\
"  #{GREEN} ooo\n"\
"  #{GREEN}ooooo\n"\
"  #{GREEN} ooo vvv       #{CLEAR}Syntropy - a web framework for Ruby\n"\
"  #{GREEN}  o vvvvv     #{CLEAR}--------------------------------------\n"\
"  #{GREEN}  #{YELLOW}|#{GREEN}  vvv o    #{CLEAR}https://github.com/digital-fabric/syntropy\n"\
"  #{GREEN} :#{YELLOW}|#{GREEN}:::#{YELLOW}|#{GREEN}::#{YELLOW}|#{GREEN}:\n"\
"#{YELLOW}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m\n\n"
VERSION =
'0.27.11'
DATE_REGEXP =
/(\d{4}-\d{2}-\d{2})/
FRONT_MATTER_REGEXP =
/\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
YAML_OPTS =
{
  permitted_classes: [Date],
  symbolize_names: true
}

Constants included from Utilities

Utilities::BUILTIN_APPLET_ROOT_DIR

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

app, builtin_applet, page_list, route_by_host

Class Attribute Details

.machineObject

Returns the value of attribute machine.



26
27
28
# File 'lib/syntropy.rb', line 26

def machine
  @machine
end

Class Method Details

.file_watch(machine, *roots, period: 0.1, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/syntropy/file_watch.rb', line 4

def self.file_watch(machine, *roots, period: 0.1, &block)
  raise 'Missing root paths' if roots.empty?

  require 'listen'

  queue = Thread::Queue.new
  listener = Listen.to(*roots) do |modified, added, removed|
    modified.each { queue.push([:modified, it]) }
    added.each    { queue.push([:added, it]) }
    removed.each  { queue.push([:removed, it]) }
  end
  listener.start

  loop do
    machine.sleep(period) while queue.empty?
    event, fn = queue.shift
    block.call(event, fn)
  end
rescue StandardError => e
  p e
  p e.backtrace
ensure
  listener.stop
end

.parse_markdown_file(path, env) ⇒ Array

Parses the markdown file at the given path.

Parameters:

  • path (String)

    file path

Returns:

  • (Array)

    an tuple containing properties<Hash>, contents<String>



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/syntropy/markdown.rb', line 17

def self.parse_markdown_file(path, env)
  content = IO.read(path) || ''
  atts = {}

  # Parse date from file name
  m = path.match(DATE_REGEXP)
  atts[:date] ||= Date.parse(m[1]) if m

  if (m = content.match(FRONT_MATTER_REGEXP))
    front_matter = m[1]
    content = m.post_match

    yaml = YAML.safe_load(front_matter, **YAML_OPTS)
    atts = atts.merge(yaml)
  end

  if env[:root_dir]
    atts[:url] = path
                 .gsub(/#{env[:root_dir]}/, '')
                 .gsub(/\.md$/, '')
  end

  [atts, content]
end

.side_run(&block) ⇒ Object



28
29
30
31
32
# File 'lib/syntropy.rb', line 28

def side_run(&block)
  raise 'Syntropy.machine not set' if !@machine

  SideRun.call(@machine, &block)
end

Instance Method Details

#colorize(color_code) ⇒ Object



35
36
37
# File 'lib/syntropy.rb', line 35

def colorize(color_code)
  "\e[#{color_code}m#{self}\e[0m"
end