Class: Frap::Generators::FlutterConfig

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/frap/generators/flutter_config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



10
11
12
# File 'lib/frap/generators/flutter_config.rb', line 10

def self.source_root
  File.dirname(__FILE__) + '/templates/dart'
end

Instance Method Details

#configure_directoriesObject



14
15
16
17
18
# File 'lib/frap/generators/flutter_config.rb', line 14

def configure_directories
  inject_into_file("#{working_directory}/pubspec.yaml", pub_files, after: /^dependencies:.*$/)
  remove_file("#{lib_directory}/main.dart")
  invoke :create_directories
end

#create_directoriesObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/frap/generators/flutter_config.rb', line 20

def create_directories
  empty_directory("#{lib_directory}/src/animations")
  empty_directory("#{lib_directory}/src/blocs")
  empty_directory("#{lib_directory}/src/models")
  empty_directory("#{lib_directory}/src/resources")
  empty_directory("#{lib_directory}/src/config")
  empty_directory("#{lib_directory}/src/constants")
  empty_directory("#{lib_directory}/src/screens")
  empty_directory("#{lib_directory}/src/widgets")
  invoke :create_files
end

#create_filesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/frap/generators/flutter_config.rb', line 32

def create_files
  template('main.dart.erb', "#{lib_directory}/main.dart")
  template('src/constants/app_constants.dart.erb', "#{src_directory}/constants/app_constants.dart")
  template('src/resources/repository.dart.erb', "#{src_directory}/resources/repository.dart")
  template('src/app.dart.erb', "#{src_directory}/app.dart")
  template('src/animations/slide_right_route.dart.erb', "#{src_directory}/animations/slide_right_route.dart")
  template('src/config/router.dart.erb', "#{src_directory}/config/router.dart")
  template('src/constants/pages_list.dart.erb', "#{src_directory}/constants/pages_list.dart")
  template('src/constants/routing.dart.erb', "#{src_directory}/constants/routing.dart")
  template('src/screens/base.dart.erb', "#{src_directory}/screens/home_screen.dart")
  template('src/screens/undefined_route_screen.dart.erb', "#{src_directory}/screens/undefined_route_screen.dart")
  template('src/widgets/base_app_bar.dart.erb', "#{src_directory}/widgets/base_app_bar.dart")
  template('src/widgets/popup_menu_widget.dart.erb', "#{src_directory}/widgets/popup_menu_widget.dart")

  invoke :setup_pages
end

#setup_pagesObject



49
50
51
52
53
# File 'lib/frap/generators/flutter_config.rb', line 49

def setup_pages
  inject_into_file("#{src_directory}/config/router.dart", home_router, after: /^.*switch \(settings.name\) \{$/)
  inject_into_file("#{src_directory}/constants/pages_list.dart", home_route, after: /const List<Page> pages = const <Page>\[.*$/)
  append_to_file("#{src_directory}/constants/routing.dart", "const String HomeScreenRoute = '/';\n")
end