Class: Cosensee::WebContentGenerator

Inherits:
Object
  • Object
show all
Extended by:
Delegatable
Defined in:
lib/cosensee/web_content_generator.rb

Overview

convert project file to web content

Defined Under Namespace

Classes: Error

Constant Summary collapse

SEARCH_DATA_PATH =
'search.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Delegatable

delegate

Constructor Details

#initialize(option:, renderer_class:, logger:, sid:) ⇒ WebContentGenerator

Returns a new instance of WebContentGenerator.



14
15
16
17
18
19
20
# File 'lib/cosensee/web_content_generator.rb', line 14

def initialize(option:, renderer_class:, logger:, sid:)
  @option = option
  @renderer_class = renderer_class
  @logger = logger
  @sid = sid
  @skip_tailwind_execution = option.skip_tailwind_execution?
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/cosensee/web_content_generator.rb', line 12

def logger
  @logger
end

#optionObject (readonly)

Returns the value of attribute option.



12
13
14
# File 'lib/cosensee/web_content_generator.rb', line 12

def option
  @option
end

#renderer_classObject (readonly)

Returns the value of attribute renderer_class.



12
13
14
# File 'lib/cosensee/web_content_generator.rb', line 12

def renderer_class
  @renderer_class
end

#sidObject (readonly)

Returns the value of attribute sid.



12
13
14
# File 'lib/cosensee/web_content_generator.rb', line 12

def sid
  @sid
end

#skip_tailwind_executionObject (readonly)

Returns the value of attribute skip_tailwind_execution.



12
13
14
# File 'lib/cosensee/web_content_generator.rb', line 12

def skip_tailwind_execution
  @skip_tailwind_execution
end

Instance Method Details

#dump_search_data(project) ⇒ Object



48
49
50
51
# File 'lib/cosensee/web_content_generator.rb', line 48

def dump_search_data(project)
  data = project.dump_search_data
  File.write(File.join(option.output_dir, SEARCH_DATA_PATH), data.to_json)
end

#execute_tailwindObject



41
42
43
44
45
46
# File 'lib/cosensee/web_content_generator.rb', line 41

def execute_tailwind
  FileUtils.mkdir_p(File.join(option.output_dir, option.css_dir))
  command = Cosensee::TailwindCommand.compile_command(output_dir: option.output_dir, css_dir: option.css_dir, debug: false)
  logger.info "Processing TailwindCSS: #{command.inspect}"
  system(*command, exception: true)
end

#generateObject

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cosensee/web_content_generator.rb', line 22

def generate
  raise Error, 'Filename is missing.' unless filename

  download_page_data(sid) if option.remote?

  raise Error, "File not found - #{filename}" unless File.exist?(filename)

  logger.info "Processing file: #{filename}"
  project = Cosensee::Project.parse_file(filename, renderer_class:)
  Cosensee::HtmlBuilder.new(project, output_dir: option.output_dir, base_url: option.base_url).build_all(clean: option.clean?)
  logger.info "Build all files into #{option.output_dir}."

  copy_js_files

  execute_tailwind unless skip_tailwind_execution

  dump_search_data(project)
end