Class: Scribo::SiteImportService
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- Scribo::SiteImportService
- Defined in:
- app/services/scribo/site_import_service.rb
Constant Summary collapse
- IGNORED_FILES =
[%r[^__MACOSX/], %r[/\.DS_Store], %r[^/_site], /^node_modules/].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#properties_override ⇒ Object
readonly
Returns the value of attribute properties_override.
-
#scribable ⇒ Object
readonly
Returns the value of attribute scribable.
Instance Method Summary collapse
-
#initialize(path, scribable: nil, properties: {}) ⇒ SiteImportService
constructor
A new instance of SiteImportService.
- #perform ⇒ Object
Methods inherited from ApplicationService
Constructor Details
#initialize(path, scribable: nil, properties: {}) ⇒ SiteImportService
Returns a new instance of SiteImportService.
13 14 15 16 17 18 |
# File 'app/services/scribo/site_import_service.rb', line 13 def initialize(path, scribable: nil, properties: {}) super() @path = path @scribable = scribable @properties_override = properties end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'app/services/scribo/site_import_service.rb', line 9 def path @path end |
#properties_override ⇒ Object (readonly)
Returns the value of attribute properties_override.
9 10 11 |
# File 'app/services/scribo/site_import_service.rb', line 9 def properties_override @properties_override end |
#scribable ⇒ Object (readonly)
Returns the value of attribute scribable.
9 10 11 |
# File 'app/services/scribo/site_import_service.rb', line 9 def scribable @scribable end |
Instance Method Details
#perform ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/services/scribo/site_import_service.rb', line 20 def perform Dir.mktmpdir do |dir| Dir.chdir(dir) do unzip(dir) all_files = Dir.glob('**/*') all_files = all_files.reject { |p| p == '_config.yml' } if properties_override.present? all_files.each do |name| parent = if File.dirname(name) == name nil else site.contents.located(File.dirname(name), restricted: false).first end content = parent.children.find_by(path: File.basename(name)) if parent content = site.contents.find_by(path: File.basename(name), parent_id: nil) if parent.nil? && content.nil? content = site.contents.create!(path: File.basename(name), parent: parent) if content.nil? if File.directory?(name) content.kind = 'folder' else File.open(name) do |f| content.kind = Scribo::Utility.kind_for_path(name) content.data_with_frontmatter = f.read end end content.save! end end end site.contents.create(path: '_config.yml', data: YAML.dump(site.properties)) if properties_override.present? site end |