Class: Jekyll::Generators::Opal
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::Generators::Opal
- Defined in:
- lib/jekyll/generators/opal.rb
Instance Method Summary collapse
- #ensure_directory(location) ⇒ Object
- #generate(site) ⇒ Object
- #keep_the_file(site) ⇒ Object
- #opal_lib_relative_path ⇒ Object
- #opal_stdlib ⇒ Object
- #output_location(site) ⇒ Object
- #save_lib_file_location_to_config(site) ⇒ Object
- #write_file(location) ⇒ Object
Instance Method Details
#ensure_directory(location) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/jekyll/generators/opal.rb', line 25 def ensure_directory(location) dir = File.dirname(location) unless File.directory?(dir) require 'fileutils' FileUtils.mkdir_p(dir) end end |
#generate(site) ⇒ Object
7 8 9 10 11 |
# File 'lib/jekyll/generators/opal.rb', line 7 def generate(site) write_file(output_location(site)) unless File.file?(output_location(site)) keep_the_file(site) save_lib_file_location_to_config(site) end |
#keep_the_file(site) ⇒ Object
37 38 39 |
# File 'lib/jekyll/generators/opal.rb', line 37 def keep_the_file(site) (site.keep_files ||= []) << opal_lib_relative_path end |
#opal_lib_relative_path ⇒ Object
50 51 52 |
# File 'lib/jekyll/generators/opal.rb', line 50 def opal_lib_relative_path Jekyll::Opal::OPAL_LIB_LOCATION end |
#opal_stdlib ⇒ Object
21 22 23 |
# File 'lib/jekyll/generators/opal.rb', line 21 def opal_stdlib ::Opal::Builder.build('opal') end |
#output_location(site) ⇒ Object
33 34 35 |
# File 'lib/jekyll/generators/opal.rb', line 33 def output_location(site) File.(opal_lib_relative_path, site.dest) end |
#save_lib_file_location_to_config(site) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/jekyll/generators/opal.rb', line 41 def save_lib_file_location_to_config(site) site.config["opal"] = { "version" => ::Opal::VERSION, # must start with a forward slash! "url" => File.join("", opal_lib_relative_path) } end |
#write_file(location) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/jekyll/generators/opal.rb', line 13 def write_file(location) ensure_directory(location) File.open(location, 'wb') do |f| f.puts(opal_stdlib) end location end |