From 4f01d2f57c69c4649a053a262082559d41115504 Mon Sep 17 00:00:00 2001 From: Todd Werth Date: Sun, 19 Apr 2015 14:02:10 -0700 Subject: [PATCH] Fixed a bug in live stylesheets and ApplicationStylesheet. Tweaked it some. --- app/stylesheets/application_stylesheet.rb | 2 -- motion/ext.rb | 39 +++++++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/stylesheets/application_stylesheet.rb b/app/stylesheets/application_stylesheet.rb index 20ce11f..845f2a5 100644 --- a/app/stylesheets/application_stylesheet.rb +++ b/app/stylesheets/application_stylesheet.rb @@ -1,6 +1,4 @@ class ApplicationStylesheet < RubyMotionQuery::Stylesheet - PADDING = 10 - def application_setup font_family = 'Helvetica Neue' font.add_named :large, font_family, 36 diff --git a/motion/ext.rb b/motion/ext.rb index 923a4cd..3d42aa1 100644 --- a/motion/ext.rb +++ b/motion/ext.rb @@ -70,35 +70,46 @@ def rmq_live_stylesheets(interval = 0.5, debug=false) private def enable_rmq_live_stylesheets(interval) - # Get list of stylesheet files return unless root_path = RubyMotionQuery::RMQ.project_path + # Get list of stylesheet files path_query = "#{root_path}/app/stylesheets/*.rb" - puts path_query if @live_reload_debug stylesheet_file_paths = Dir.glob(path_query) - stylesheet_file_paths.delete_if{|stylesheet| stylesheet =~ /application_stylesheet\.rb$/} - puts stylesheet_file_paths if @live_reload_debug stylesheets = stylesheet_file_paths.inject({}) do |out, stylesheet_path_file| - out[stylesheet_path_file] = RubyMotionQuery::RMQ.build_time + klass_name = File.basename(stylesheet_path_file, '.rb') + klass_name = klass_name.gsub("_", " ").gsub(/\b(? modified_date - code = File.read(stylesheet) - puts "Reloaded #{stylesheet}." if @live_reload_debug + stylesheets.each do |key, stylesheet| + + modified_at = File.mtime(stylesheet[:path]) + if modified_at > stylesheet[:modified] + code = File.read(stylesheet[:path]) + puts "Reloaded #{stylesheet[:class_name]}" if @live_reload_debug eval(code) - stylesheets[stylesheet] = File.mtime(stylesheet) + stylesheet[:modified] = modified_at style_changed = true end + end - if style_changed - vc_rmq = rmq.view_controller.rmq - vc_rmq.all.and_self.reapply_styles - end + + rmq.view_controller.rmq.all.and_self.reapply_styles if style_changed end "Live reloading of RMQ stylesheets is now on."