fix a lot of tiny bugs (not yet) + testing import tool
This commit is contained in:
parent
9a722c4268
commit
e31012f861
@ -1,12 +1,12 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: git://github.com/locomotivecms/custom_fields.git
|
remote: git://github.com/locomotivecms/custom_fields.git
|
||||||
revision: 89c4d7d
|
revision: 89c4d7d21efa4c4715c0e34edcc9ce22c405dcd4
|
||||||
specs:
|
specs:
|
||||||
custom_fields (0.0.0.2)
|
custom_fields (0.0.0.2)
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/locomotivecms/liquid.git
|
remote: git://github.com/locomotivecms/liquid.git
|
||||||
revision: b03cdc2
|
revision: b03cdc289ac36c3395459e295c6bf90baa06d256
|
||||||
ref: b03cdc289ac36c339545
|
ref: b03cdc289ac36c339545
|
||||||
specs:
|
specs:
|
||||||
liquid (2.1.3)
|
liquid (2.1.3)
|
||||||
@ -79,7 +79,7 @@ GEM
|
|||||||
git (1.2.5)
|
git (1.2.5)
|
||||||
haml (3.0.18)
|
haml (3.0.18)
|
||||||
has_scope (0.5.0)
|
has_scope (0.5.0)
|
||||||
heroku (1.10.5)
|
heroku (1.10.6)
|
||||||
json_pure (>= 1.2.0, < 1.5.0)
|
json_pure (>= 1.2.0, < 1.5.0)
|
||||||
launchy (~> 0.3.2)
|
launchy (~> 0.3.2)
|
||||||
rest-client (~> 1.4.0)
|
rest-client (~> 1.4.0)
|
||||||
@ -126,7 +126,7 @@ GEM
|
|||||||
rack (1.2.1)
|
rack (1.2.1)
|
||||||
rack-mount (0.6.13)
|
rack-mount (0.6.13)
|
||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
rack-test (0.5.4)
|
rack-test (0.5.5)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
rails (3.0.0)
|
rails (3.0.0)
|
||||||
actionmailer (= 3.0.0)
|
actionmailer (= 3.0.0)
|
||||||
|
@ -61,7 +61,7 @@ module Models
|
|||||||
context = default_context.merge(context)
|
context = default_context.merge(context)
|
||||||
|
|
||||||
@template = ::Liquid::Template.parse(self.raw_template, context)
|
@template = ::Liquid::Template.parse(self.raw_template, context)
|
||||||
|
|
||||||
self.template_dependencies = context[:templates]
|
self.template_dependencies = context[:templates]
|
||||||
self.snippet_dependencies = context[:snippets]
|
self.snippet_dependencies = context[:snippets]
|
||||||
|
|
||||||
|
@ -26,11 +26,14 @@ class Snippet
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def normalize_slug
|
def normalize_slug
|
||||||
|
# TODO: refactor it
|
||||||
self.slug = self.name.clone if self.slug.blank? && self.name.present?
|
self.slug = self.name.clone if self.slug.blank? && self.name.present?
|
||||||
self.slug.slugify!(:without_extension => true, :downcase => true) if self.slug.present?
|
self.slug.slugify!(:without_extension => true, :downcase => true) if self.slug.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_templates
|
def update_templates
|
||||||
|
return unless (self.site rescue nil) # not run if the site is being destroyed
|
||||||
|
|
||||||
pages = self.site.pages.any_in(:snippet_dependencies => [self.slug]).to_a
|
pages = self.site.pages.any_in(:snippet_dependencies => [self.slug]).to_a
|
||||||
|
|
||||||
pages.each do |page|
|
pages.each do |page|
|
||||||
@ -44,7 +47,7 @@ class Snippet
|
|||||||
case node
|
case node
|
||||||
when Locomotive::Liquid::Tags::Snippet
|
when Locomotive::Liquid::Tags::Snippet
|
||||||
node.refresh(self) if node.slug == self.slug
|
node.refresh(self) if node.slug == self.slug
|
||||||
when Locomotive::Liquid::Tags::Block
|
when Locomotive::Liquid::Tags::InheritedBlock
|
||||||
self._change_snippet_inside_template(node.parent) if node.parent
|
self._change_snippet_inside_template(node.parent) if node.parent
|
||||||
else
|
else
|
||||||
if node.respond_to?(:nodelist)
|
if node.respond_to?(:nodelist)
|
||||||
|
@ -125,7 +125,9 @@ class ThemeAsset
|
|||||||
end
|
end
|
||||||
|
|
||||||
def extname_can_not_be_changed
|
def extname_can_not_be_changed
|
||||||
return if self.new_record?
|
return if self.new_record? || self.source.file.original_filename.nil?
|
||||||
|
|
||||||
|
puts "filename => #{self.source_filename} / source file => #{self.source.file.inspect}"
|
||||||
|
|
||||||
if File.extname(self.source.file.original_filename) != File.extname(self.source_filename)
|
if File.extname(self.source.file.original_filename) != File.extname(self.source_filename)
|
||||||
self.errors.add(:source, :extname_changed)
|
self.errors.add(:source, :extname_changed)
|
||||||
|
7
doc/TODO
7
doc/TODO
@ -23,6 +23,13 @@ x create a repo for a tool "a la" vision
|
|||||||
- write my first tutorial about locomotive
|
- write my first tutorial about locomotive
|
||||||
- asset collections => liquid
|
- asset collections => liquid
|
||||||
- apply http://github.com/flori/json/commit/2c0f8d2c9b15a33b8d10ffcb1959aef54d320b57
|
- apply http://github.com/flori/json/commit/2c0f8d2c9b15a33b8d10ffcb1959aef54d320b57
|
||||||
|
- snippet dependencies => do not work correctly
|
||||||
|
- images tag to write
|
||||||
|
- import tool:
|
||||||
|
- disable sub tasks by passing options
|
||||||
|
- select field (see custom fields and nocoffee theme) ?
|
||||||
|
- exceptions
|
||||||
|
- page to import theme
|
||||||
|
|
||||||
- refactor slugify method (use parameterize + create a module)
|
- refactor slugify method (use parameterize + create a module)
|
||||||
- [content types] the "display column" selector should not include file types
|
- [content types] the "display column" selector should not include file types
|
||||||
|
@ -19,6 +19,7 @@ module Locomotive
|
|||||||
slug = File.basename(asset_path, File.extname(asset_path)).parameterize('_')
|
slug = File.basename(asset_path, File.extname(asset_path)).parameterize('_')
|
||||||
|
|
||||||
asset = site.theme_assets.where(:content_type => kind.singularize, :slug => slug).first
|
asset = site.theme_assets.where(:content_type => kind.singularize, :slug => slug).first
|
||||||
|
|
||||||
asset ||= site.theme_assets.build
|
asset ||= site.theme_assets.build
|
||||||
|
|
||||||
asset.attributes = { :source => File.open(asset_path), :performing_plain_text => false }
|
asset.attributes = { :source => File.open(asset_path), :performing_plain_text => false }
|
||||||
@ -36,7 +37,7 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.add_other_assets(site, theme_path)
|
def self.add_other_assets(site, theme_path)
|
||||||
collection = AssetCollection.find_or_create_internal(current_site)
|
collection = AssetCollection.find_or_create_internal(site)
|
||||||
|
|
||||||
Dir[File.join(theme_path, 'public', 'samples', '*')].each do |asset_path|
|
Dir[File.join(theme_path, 'public', 'samples', '*')].each do |asset_path|
|
||||||
|
|
||||||
|
@ -16,9 +16,7 @@ module Locomotive
|
|||||||
|
|
||||||
self.add_or_update_fields(content_type, attributes['fields'])
|
self.add_or_update_fields(content_type, attributes['fields'])
|
||||||
|
|
||||||
content_type.save
|
content_type.save!
|
||||||
|
|
||||||
# puts "content_type = #{content_type.inspect}"
|
|
||||||
|
|
||||||
site.reload
|
site.reload
|
||||||
end
|
end
|
||||||
@ -34,7 +32,7 @@ module Locomotive
|
|||||||
|
|
||||||
def self.add_or_update_fields(content_type, fields)
|
def self.add_or_update_fields(content_type, fields)
|
||||||
fields.each do |name, data|
|
fields.each do |name, data|
|
||||||
attributes = { :_name => name, :kind => 'String' }.merge(data).symbolize_keys
|
attributes = { :label => name.humanize, :_name => name, :kind => 'String' }.merge(data).symbolize_keys
|
||||||
|
|
||||||
field = content_type.content_custom_fields.detect { |f| f._name == attributes[:_name] }
|
field = content_type.content_custom_fields.detect { |f| f._name == attributes[:_name] }
|
||||||
|
|
||||||
|
@ -22,14 +22,14 @@ module Locomotive
|
|||||||
:site => @site,
|
:site => @site,
|
||||||
:theme_path => @theme_path
|
:theme_path => @theme_path
|
||||||
}
|
}
|
||||||
|
|
||||||
Locomotive::Import::Site.process(context)
|
Locomotive::Import::Site.process(context)
|
||||||
|
|
||||||
Locomotive::Import::ContentTypes.process(context)
|
Locomotive::Import::ContentTypes.process(context)
|
||||||
|
|
||||||
# Locomotive::Import::Assets.process(context)
|
# Locomotive::Import::Assets.process(context)
|
||||||
|
|
||||||
# Locomotive::Import::Snippets.process(context)
|
Locomotive::Import::Snippets.process(context)
|
||||||
|
|
||||||
Locomotive::Import::Pages.process(context)
|
Locomotive::Import::Pages.process(context)
|
||||||
end
|
end
|
||||||
@ -39,6 +39,8 @@ module Locomotive
|
|||||||
def unzip!
|
def unzip!
|
||||||
Zip::ZipFile.open(@theme_file) do |zipfile|
|
Zip::ZipFile.open(@theme_file) do |zipfile|
|
||||||
destination_path = File.join(Rails.root, 'tmp', 'themes', @site.id.to_s)
|
destination_path = File.join(Rails.root, 'tmp', 'themes', @site.id.to_s)
|
||||||
|
|
||||||
|
FileUtils.rm_r destination_path, :force => true
|
||||||
|
|
||||||
zipfile.each do |entry|
|
zipfile.each do |entry|
|
||||||
next if entry.name =~ /__MACOSX/
|
next if entry.name =~ /__MACOSX/
|
||||||
|
@ -4,14 +4,16 @@ module Locomotive
|
|||||||
|
|
||||||
def self.process(context)
|
def self.process(context)
|
||||||
site, pages, theme_path = context[:site], context[:database]['pages'], context[:theme_path]
|
site, pages, theme_path = context[:site], context[:database]['pages'], context[:theme_path]
|
||||||
|
|
||||||
|
context[:done] = {} # initialize the hash storing pages already processed
|
||||||
|
|
||||||
self.add_index_and_404(context)
|
self.add_index_and_404(context)
|
||||||
|
|
||||||
Dir[File.join(theme_path, 'templates', '**/*')].each do |template_path|
|
Dir[File.join(theme_path, 'templates', '**/*')].each do |template_path|
|
||||||
|
|
||||||
fullpath = template_path.gsub(File.join(theme_path, 'templates'), '')
|
fullpath = template_path.gsub(File.join(theme_path, 'templates'), '').gsub('.liquid', '').gsub(/^\//, '')
|
||||||
|
|
||||||
puts "fullpath = #{fullpath}"
|
puts "=========== #{fullpath} ================="
|
||||||
|
|
||||||
next if %w(index 404).include?(fullpath)
|
next if %w(index 404).include?(fullpath)
|
||||||
|
|
||||||
@ -19,17 +21,31 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_page(fullpath, context)
|
def self.add_page(fullpath, context)
|
||||||
site = context[:site]
|
puts "....adding #{fullpath}"
|
||||||
|
|
||||||
|
page = context[:done][fullpath]
|
||||||
|
|
||||||
|
return page if page # already added, so skip it
|
||||||
|
|
||||||
|
site, pages, theme_path = context[:site], context[:database]['site']['pages'], context[:theme_path]
|
||||||
|
|
||||||
|
template = File.read(File.join(theme_path, 'templates', "#{fullpath}.liquid"))
|
||||||
|
|
||||||
|
self.build_parent_template(template, context)
|
||||||
|
|
||||||
parent = self.find_parent(fullpath, context)
|
parent = self.find_parent(fullpath, context)
|
||||||
|
|
||||||
puts "adding #{fullpath}"
|
puts "updating..... #{fullpath} / #{template}"
|
||||||
|
|
||||||
page = site.pages.where(:fullpath => fullpath).first || site.pages.build
|
page = site.pages.where(:fullpath => fullpath).first || site.pages.build
|
||||||
|
|
||||||
attributes = { :fullpath => fullpath, :parent => parent }.merge(context[:database]['pages'][fullpath] || {})
|
attributes = {
|
||||||
attributes.symbolize_keys!
|
:title => fullpath.split('/').last.humanize,
|
||||||
|
:slug => fullpath.split('/').last,
|
||||||
|
:parent => parent,
|
||||||
|
:raw_template => template
|
||||||
|
}.merge(pages[fullpath] || {}).symbolize_keys
|
||||||
|
|
||||||
# templatized ?
|
# templatized ?
|
||||||
if content_type_slug = attributes.delete(:content_type)
|
if content_type_slug = attributes.delete(:content_type)
|
||||||
@ -39,21 +55,49 @@ module Locomotive
|
|||||||
page.attributes = attributes
|
page.attributes = attributes
|
||||||
|
|
||||||
# do not parse liquid templates now
|
# do not parse liquid templates now
|
||||||
page.instance_variable_set(:@template_changed, false)
|
# page.instance_variable_set(:@template_changed, false)
|
||||||
|
|
||||||
page.save!
|
page.save!
|
||||||
|
|
||||||
site.reload
|
site.reload
|
||||||
|
|
||||||
|
context[:done][fullpath] = page
|
||||||
|
|
||||||
|
page
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.build_parent_template(template, context)
|
||||||
|
puts "building parent_template #{template.blank?}"
|
||||||
|
|
||||||
|
# just check if the template contains the extends keyword
|
||||||
|
# template
|
||||||
|
fullpath = template.scan(/\{% extends (\w+) %\}/).flatten.first
|
||||||
|
|
||||||
|
if fullpath # inheritance detected
|
||||||
|
fullpath.gsub!("'", '')
|
||||||
|
|
||||||
|
puts "found parent_template #{fullpath}"
|
||||||
|
|
||||||
|
return if fullpath == 'parent'
|
||||||
|
|
||||||
|
self.add_page(fullpath, context)
|
||||||
|
else
|
||||||
|
puts "no parent_template found #{fullpath}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_parent(fullpath, context)
|
def self.find_parent(fullpath, context)
|
||||||
|
puts "finding parent for #{fullpath}"
|
||||||
|
|
||||||
|
site = context[:site]
|
||||||
|
|
||||||
segments = fullpath.split('/')
|
segments = fullpath.split('/')
|
||||||
|
|
||||||
return site.pages.index.first if segments.empty?
|
return site.pages.index.first if segments.size == 1
|
||||||
|
|
||||||
(segments.last == 'index' ? 2 : 1).times { segments.pop }
|
(segments.last == 'index' ? 2 : 1).times { segments.pop }
|
||||||
|
|
||||||
parent_fullpath = File.join(segments.join('/'), 'index')
|
parent_fullpath = File.join(segments.join('/'), 'index').gsub(/^\//, '')
|
||||||
|
|
||||||
# look for a local index page in db
|
# look for a local index page in db
|
||||||
parent = site.pages.where(:fullpath => parent_fullpath).first
|
parent = site.pages.where(:fullpath => parent_fullpath).first
|
||||||
@ -61,19 +105,25 @@ module Locomotive
|
|||||||
parent || self.add_page(parent_fullpath, context)
|
parent || self.add_page(parent_fullpath, context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_index_and_404(context)
|
def self.add_index_and_404(context)
|
||||||
site, database = context[:site], context[:database]
|
site, pages, theme_path = context[:site], context[:database]['site']['pages'], context[:theme_path]
|
||||||
|
|
||||||
%w(index 404).each do |slug|
|
%w(index 404).each do |slug|
|
||||||
page = site.pages.where({ :slug => slug, :depth => 0 }).first
|
page = site.pages.where({ :slug => slug, :depth => 0 }).first
|
||||||
|
|
||||||
|
# puts "building system page (#{slug}) => #{page.inspect}"
|
||||||
|
|
||||||
page ||= sites.pages.build(:slug => slug, :parent => nil)
|
page ||= sites.pages.build(:slug => slug, :parent => nil)
|
||||||
|
|
||||||
|
template = File.read(File.join(theme_path, 'templates', "#{slug}.liquid"))
|
||||||
|
|
||||||
page.attributes = database['pages'][slug]
|
page.attributes = { :raw_template => template }.merge(pages[slug] || {})
|
||||||
|
|
||||||
page.save!
|
page.save! rescue nil # TODO better error handling
|
||||||
|
|
||||||
site.reload
|
site.reload
|
||||||
|
|
||||||
|
context[:done][slug] = page
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@ module Locomotive
|
|||||||
site.attributes = attributes
|
site.attributes = attributes
|
||||||
|
|
||||||
site.save!
|
site.save!
|
||||||
|
|
||||||
puts "site errors = #{site.errors.inspect}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -8,9 +8,12 @@ module Locomotive
|
|||||||
Dir[File.join(theme_path, 'snippets', '*')].each do |snippet_path|
|
Dir[File.join(theme_path, 'snippets', '*')].each do |snippet_path|
|
||||||
|
|
||||||
name = File.basename(snippet_path, File.extname(snippet_path)).parameterize('_')
|
name = File.basename(snippet_path, File.extname(snippet_path)).parameterize('_')
|
||||||
|
|
||||||
|
snippet = site.snippets.where(:slug => name).first || site.snippets.build(:name => name)
|
||||||
|
|
||||||
snippet = site.snippets.create! :name => name, :template => File.read(snippet_path)
|
snippet.template = File.read(snippet_path) # = site.snippets.create! :name => name, :template =>
|
||||||
|
|
||||||
|
snippet.save!
|
||||||
# puts "snippet = #{snippet.inspect}"
|
# puts "snippet = #{snippet.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Locomotive
|
|||||||
|
|
||||||
def end_tag
|
def end_tag
|
||||||
super
|
super
|
||||||
|
|
||||||
if !self.contains_super?(@nodelist) # then disable all editable_elements coming from the parent block too and not used
|
if !self.contains_super?(@nodelist) # then disable all editable_elements coming from the parent block too and not used
|
||||||
@context[:page].disable_parent_editable_elements(@name)
|
@context[:page].disable_parent_editable_elements(@name)
|
||||||
end
|
end
|
||||||
@ -17,7 +17,7 @@ module Locomotive
|
|||||||
nodelist.any? do |node|
|
nodelist.any? do |node|
|
||||||
if node.is_a?(::Liquid::Variable) && node.name == 'block.super'
|
if node.is_a?(::Liquid::Variable) && node.name == 'block.super'
|
||||||
true
|
true
|
||||||
elsif node.respond_to?(:nodelist) && !node.is_a?(Locomotive::Liquid::Tags::InheritedBlock)
|
elsif node.respond_to?(:nodelist) && !node.nodelist.nil? && !node.is_a?(Locomotive::Liquid::Tags::InheritedBlock)
|
||||||
contains_super?(node.nodelist)
|
contains_super?(node.nodelist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -81,6 +81,9 @@ end
|
|||||||
# # empty page (imac 27'): User System Total Real
|
# # empty page (imac 27'): User System Total Real
|
||||||
# Rendering page 10k times 21.390000 1.820000 23.210000 ( 24.120529)
|
# Rendering page 10k times 21.390000 1.820000 23.210000 ( 24.120529)
|
||||||
|
|
||||||
|
# # empty page (mac mini core 2 duo / 2Go): User System Total Real
|
||||||
|
# Rendering a simple page 10k times 17.130000 0.420000 17.550000 ( 19.459768)
|
||||||
|
|
||||||
# # page with inherited template (imac 27'): User System Total Real
|
# # page with inherited template (imac 27'): User System Total Real
|
||||||
# Rendering page 10k times 85.840000 7.600000 93.440000 ( 97.841248)
|
# Rendering page 10k times 85.840000 7.600000 93.440000 ( 97.841248)
|
||||||
|
|
||||||
@ -89,3 +92,8 @@ end
|
|||||||
|
|
||||||
# # with locomotive liquid (imac 27'): User System Total Real
|
# # with locomotive liquid (imac 27'): User System Total Real
|
||||||
# Rendering page 10k times 38.750000 3.050000 41.800000 ( 42.880022)
|
# Rendering page 10k times 38.750000 3.050000 41.800000 ( 42.880022)
|
||||||
|
|
||||||
|
# # with locomotive liquid (mac mini core 2 duo / 2Go): User System Total Real
|
||||||
|
# Rendering a complex page 10k times 30.840000 0.530000 31.370000 ( 32.847565)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user